-
Notifications
You must be signed in to change notification settings - Fork 576
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
Roll back invalid object creations not handled by realm.write()
#6356
base: main
Are you sure you want to change the base?
Conversation
export type ObjCreator = () => [binding.Obj, boolean]; | ||
export type ObjCreator = () => [binding.Obj, boolean, binding.TableRef?]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it's now 3 values, we could choose to return an object instead to clarify the return values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this is approaching (if its not already in) the territory that needs an object 👍
In this specific case, we might not need to pass the TableRef
here at all, but we could instead pass a "rollback", "revert" or "delete" function, taking no arguments, which will call table.removeObject(obj.key)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the TableRef
really optional? Maybe i'm overlooking something, but the creator seems to always return a TableRef
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..but we could instead pass a "rollback", "revert" or "delete" function, taking no arguments..
Interesting, yeah that seems more appropriate given that that's the only reason for passing the table
🙂
Is the
TableRef
really optional?
The creator defined on the Object class will always return the table
, but for embedded objects, a custom createObj()
method will be passed as part of the CreationContext
. As those parts have not been modified, the table ref needed to be optional in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have a small suggestion 👍 But this can merge as is if you want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great fix!
What, How & Why?
Trying to create an invalid object (e.g. missing required properties) via
realm.create()
or aRealm.Object
constructor would both throw and create the object (with default values for required properties), causing the object creation to not be rolled back in the following cases:realm.write()
and does not rethrow it.This PR updates it so that the individual operation is automatically rolled back.
This closes #2638.
It also sets up somewhat related tests (currently
.skip
ed) that can be enabled once #6355 is fixed.☑️ ToDos