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: merge does not create the record if it does not exist #142

Open
2 tasks done
huntipl opened this issue Jan 14, 2025 · 0 comments
Open
2 tasks done

Bug: merge does not create the record if it does not exist #142

huntipl opened this issue Jan 14, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@huntipl
Copy link

huntipl commented Jan 14, 2025

Describe the bug

When calling merge with a RecordID that exists, it updates the specified fields. But when running it with RecordID that does not exist or with Table name only, it does nothing, where the same SurrealQL creates records when they do not exist.

Additionally, when running custom query with UPSERT MERGE it works as expected (creates new records).

Steps to reproduce

# Does nothing, returns None
res = await db.merge(RecordID("test", "id1"), {"key": 1})
print(f"Merge1: {res}")

# Does nothing, returns [] ???
res = await db.merge(Table("test"), {"key": 1})
print(f"Merge2: {res}")

res = await db.create(RecordID("test", "id2"), {"key": 1})
print(f"Create: {res}")

# This works fine
res = await db.merge(RecordID("test", "id2"), {"key2": 2})
print(f"Merge3: {res}")

# This also works fine
res = await db.query(""" UPSERT test MERGE {"key3":3} """)
print(f"Query: {res}")

Result:

Merge1: None
Merge2: []
Create: {'id': RecordID(table_name=test, record_id=id2), 'key': 1}
Merge3: {'id': RecordID(table_name=test, record_id=id2), 'key': 1, 'key2': 2}
Query: [{'result': [{'id': RecordID(table_name=test, record_id=taj7kiqxar7smnc7jnh6), 'key3': 3}], 'status': 'OK', 'time': '158.778µs'}]

Expected behaviour

Assuming the SurrealQL behavior of MERGE is correct, I expect the merge method of the SDK to behave the same way - so create records if they don't exist

SurrealDB version

2.1.4

surrealdb.py version

0.4.1

Contact Details

No response

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
@huntipl huntipl added the bug Something isn't working label Jan 14, 2025
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