Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Surreal.patch method #100

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python_package/surrealdb/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,10 @@ async def merge(
return success.result

async def patch(
self, thing: str, data: Optional[Dict[str, Any]]
) -> List[Dict[str, Any]]:
self,
thing: str,
data: Optional[List[Dict[str, Any]]],
) -> Union[dict[str, Any], List[Dict[str, Any]]]:
"""
Apply JSON Patch changes to all records, or a specific record, in the database.

Expand All @@ -598,6 +600,7 @@ async def patch(
{ 'op': "remove", "path": "/temp" },
])
"""
data = data or []
Copy link
Author

@Wouterkoorn Wouterkoorn Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for backwards compatibility, making the change non-breaking.
The typing was Optional, but the server requires an array, None is invalid.

response = await self._send_receive(
Request(
id=generate_uuid(),
Expand Down