You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If resetting an embedded object to an object with e.g. a missing required property, the SDK expectedly throws. If this exception is caught within the write transaction by the user, the original embedded object will still be updated but with default values.
Since our call into Core's obj.create_and_set_linked_object() is made prior to setting the user-provided values, the values on the embedded object have been set to default values.
Example test (this test has already been set up by PR #6356):
// Create a valid object with a valid embedded object (`address`).constamy=this.realm.write(()=>{returnthis.realm.create(PersonWithEmbeddedSchema.name,{name: "Amy",age: 30,address: {street: "Broadway"},});});expect(this.realm.objects(PersonWithEmbeddedSchema.name).length).equals(1);expect(amy.address?.street).equals("Broadway");// Update the embedded object with an invalid one.this.realm.write(()=>{// It is important to catch the exception within `realm.write()` in order to test// that the object creation path does not modify the object (rather than being due// to `realm.write()` cancelling the transaction).expect(()=>{constinvalidEmbeddedAddress={};// @ts-expect-error Testing setting invalid type.amy.address=invalidEmbeddedAddress;}).to.throw("Missing value for property 'street'");});constobjects=this.realm.objects<IPersonWithEmbedded>(PersonWithEmbeddedSchema.name);expect(objects.length).equals(1);expect(objects[0].address).to.not.be.null;// 💥 Fails: `street` will be the default value (empty string).expect(objects[0].address?.street).equals("Broadway");
The text was updated successfully, but these errors were encountered:
If resetting an embedded object to an object with e.g. a missing required property, the SDK expectedly throws. If this exception is caught within the write transaction by the user, the original embedded object will still be updated but with default values.
Since our call into Core's
obj.create_and_set_linked_object()
is made prior to setting the user-provided values, the values on the embedded object have been set to default values.Example test (this test has already been set up by PR #6356):
The text was updated successfully, but these errors were encountered: