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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: db.insert throws an error if the user provides a RecordId object #369

Open
2 tasks done
knackstedt opened this issue Nov 11, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@knackstedt
Copy link
Contributor

Describe the bug

There is an issue with the error the SDK throws when incorrectly using the insert method.

These will fail always:

  • await db.insert(new RecordId('foobar', '789'), { thing: true });
  • await db.insert({ id: "foobar:741", thing: true });

Both yield this error:

ResponseError: There was a problem with the database: Can not execute INSERT statement using value 'foobar:⟨789⟩'
    at Surreal.insert (/home/knackstedt/source/test/surrealdb-2/node_modules/surrealdb/dist/index.cjs:1:51805)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/knackstedt/source/test/surrealdb-2/src/main.ts:31:5

However, using this syntax will only fail if the record already exists. Otherwise it will successfully insert a record into the "foobar" table.
await db.insert("foobar", { id: "exact_id1", thing: true });

This behavior is different and either needs to be documented that it's intentional or reviewed for where it departs from the expected behaviour -- I honestly don't know what the real intention is for the behavior here but this isn't clear from the API that this is how the SDK intends to behave.

Personally, if the intention is to be strict, please throw errors from the client where a developer or the input is invalid. This makes it much easier to debug where something is being done incorrectly.

Steps to reproduce

Install Surrealdb 2.x.x and get the JS SDK 1.0.6

Expected behaviour

The error should be checked on the client side, and throw something like "Cannot insert value with ID, use upsert instead."

SurrealDB version

2.0.4 for linux on x86_64

JavaScript SDK version

1.0.6

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@knackstedt knackstedt added the bug Something isn't working label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant