surrealdb / surrealdb.py

SurrealDB SDK for Python
https://surrealdb.com
Apache License 2.0
170 stars 49 forks source link

Bug: patch method broken (request method name & typing) #99

Open Wouterkoorn opened 3 months ago

Wouterkoorn commented 3 months ago

Describe the bug

The Surreal.patch method is currently broken due to the wrong method name being used in the request. It is also wrongly typed, the expected input should be a list of dict, not a sole dict. And the return type should allow a single dict.

Steps to reproduce

Currently:

await db.update("table:id", {"field": "value"})

surrealdb.ws.SurrealPermissionException: Method not found


After changing the Request method in Surreal.patch from "modify" to "patch":

await db.update("table:id", {"field": "value"})

surrealdb.ws.SurrealPermissionException: There was a problem with the database: The JSON Patch contains invalid operations. Operations must be an array


Now using an array as documented here: https://surrealdb.com/docs/surrealdb/integration/websocket#patch

await db.patch("table:id", [
    {"op": "replace", "path": "/field", "value": "value"}
])

Success! But typing of both the data param, and the return type, is still wrong.

Expected behaviour

  1. The request method name should be changed from "modify" to "patch", similar to https://github.com/surrealdb/surrealdb.py/pull/85
  2. The data parameter should by typed to expect an Array, e.g. List[Dict[str, Any]]
  3. The return type allows a single dict, same as https://github.com/surrealdb/surrealdb.py/issues/97

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: 6qmf6te8@duck.com

Is there an existing issue for this?

Code of Conduct