You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most methods return annotations are List[Dict[str, Any]].
This is correct when querying for (potentially) multiple items like Surreal.select("table"), without supplying a specific ID.
This is incorrect when querying with a specific ID, like Surreal.select("table:id"). Instead of a list of dicts, it directly returns a single dict.
Another thing missing in the typing of Optional. When select or delete get supplied a non-existent ID, the method returns None.
These issues only seem to be the case with Surreal (WS/RPC client), and not with SurrealHTTP, which does always return a list.
While all methods are typed to return type of <class 'list'>
Expected behaviour
I can see a few options to resolve this, listed below with their pros and cons:
Change the typing of the affected methods, e.g. Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]
+ This is a non-breaking change, only affecting type annotations
Use type overloading, annotating either list or dict
- This will only work if the id becomes a separate optional parameter - breaking change
+ More precise typing than Union
Only return list, as it is currently typed
- This would not change the typing, but instead adjust the return value to the existing type - breaking change
+ This would make the Surreal and SurrealHTTP classes more aligned, returning the same types.
My opinion would be to implement idea number 1 now, as it is non-breaking. And keep the other ideas open for a breaking version bump (1.0?)
Please feel free to suggest other ideas as well.
And note, I'm more than happy to create the PR once we've decided on the desired solution.
Describe the bug
Most methods return annotations are
List[Dict[str, Any]]
.This is correct when querying for (potentially) multiple items like
Surreal.select("table")
, without supplying a specific ID.This is incorrect when querying with a specific ID, like
Surreal.select("table:id")
. Instead of a list of dicts, it directly returns a single dict.Another thing missing in the typing of
Optional
. Whenselect
ordelete
get supplied a non-existent ID, the method returnsNone
.These issues only seem to be the case with
Surreal
(WS/RPC client), and not withSurrealHTTP
, which does always return a list.Steps to reproduce
results in:
While all methods are typed to return type of
<class 'list'>
Expected behaviour
I can see a few options to resolve this, listed below with their pros and cons:
Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]
+ This is a non-breaking change, only affecting type annotations
list
ordict
- This will only work if the id becomes a separate optional parameter - breaking change
+ More precise typing than
Union
- This would not change the typing, but instead adjust the return value to the existing type - breaking change
+ This would make the
Surreal
andSurrealHTTP
classes more aligned, returning the same types.My opinion would be to implement idea number 1 now, as it is non-breaking. And keep the other ideas open for a breaking version bump (1.0?)
Please feel free to suggest other ideas as well.
And note, I'm more than happy to create the PR once we've decided on the desired solution.
SurrealDB version
1.3.1 for linux on x86_64
surrealdb.py version
0.3.2 (latest as of 2024-04-02)
Contact Details
Ideally in the issue itself. Otherwise: [email protected]
Is there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: