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

Creating objects while in a manual transaction, should either create an object or throw #2638

Open
kraenhansen opened this issue Dec 6, 2019 · 3 comments · May be fixed by #6356
Open

Creating objects while in a manual transaction, should either create an object or throw #2638

kraenhansen opened this issue Dec 6, 2019 · 3 comments · May be fixed by #6356
Labels

Comments

@kraenhansen
Copy link
Member

kraenhansen commented Dec 6, 2019

Goals

Calls to realm.create() should either create an object or throw (while in a manual transaction).

Expected Results

If realm.create throws, I expect no side-effects on the database (ie. no rows with default values created).

Actual Results

Calling realm.create with missing values, while in a manual transaction throws but also creates an object with default values.

Steps to Reproduce & Code Sample

const Realm = require("realm");
const realm = new Realm({ schema: [ { name: "SomeClass", properties: { name: 'string', age: 'int' } } ] });
realm.beginTransaction();
realm.create('SomeClass', { age: 13 })

☝️ throws

Error: Missing value for property 'SomeClass.name'

Listing the objects afterwards reveals an object was actually created:

realm.objects('SomeClass') //  Results { [0]: RealmObject { [name]: '', [age]: 0 } }

Version of Realm and Tooling

  • Realm JS SDK Version: 3.5.0
  • Node or React Native: N/A
  • Client OS & Version: N/A
  • Which debugger for React Native: None
@kneth
Copy link
Contributor

kneth commented Dec 10, 2019

My opinion is that manual transactions require a try/catch i.e., you have the responsibility to react on errors/exceptions. We should clarify this in the documentation.

@kraenhansen
Copy link
Member Author

As minimum, we should clarify the documentation on the callers responsibility to cancel the transaction if any errors are thrown while interacting with it.

I still think this is a bug though. It should either throw or create the object with the properties. I believe its an (highly unexpected) artifact of the implementation that the database can be left in a state where the object is created, but without values for its properties.

@kraenhansen
Copy link
Member Author

I talked with @jedelbo about this and it turns out Core 6 has a method to create an object, with values which might be a great way to implement a fix for this issue (https://github.com/realm/realm-core/blob/next-major/src/realm/table.hpp#L274-L279).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants