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

UpdateMode doesn't get passed recursively when creating child objects in realm v12 #5933

Closed
chvllad opened this issue Jun 25, 2023 · 1 comment · Fixed by #5944
Closed

UpdateMode doesn't get passed recursively when creating child objects in realm v12 #5933

chvllad opened this issue Jun 25, 2023 · 1 comment · Fixed by #5944

Comments

@chvllad
Copy link

chvllad commented Jun 25, 2023

How frequently does the bug occur?

Always

Description

Realm v12.0.0-alpha.2 always use UpdateMode.Never for children objects ignoring mode arg in create function:

// TODO: Consider exposing a way for calling code to disable object creation
assert.object(value, name);
// Some other object is assumed to be an unmanged object, that the user wants to create
const createdObject = RealmObject.create(realm, value, UpdateMode.Never, {
helpers,
createObj,
});
return createdObject[INTERNAL];

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

Code:

import Realm, { UpdateMode } from "realm";

const ASchema = {
  name: "A",
  primaryKey: "id",
  properties: {
    id: "int",
  },
};

const BSchema = {
  name: "B",
  properties: {
    a: "A[]",
  },
};

const realm = new Realm({
  schema: [ASchema, BSchema],
  schemaVersion: 0,
  inMemory: true,
  path: "temp_db",
});

realm.write(() => {
  realm.create("A", {
    id: 1,
  });
  realm.create("B", {
    a: [{ id: 1 }],
  }, UpdateMode.All);
});

Expected

Successful creation

Actual

Error: Attempting to create an object of type 'A' with an existing primary key value '1'., js engine: hermes

Version

12.0.0-alpha.2

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

React-native; Android, IOS

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

@kraenhansen
Copy link
Member

Thanks for reporting this! I'll put it top of the backlog.

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

Successfully merging a pull request may close this issue.

2 participants