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

@realm/babel-plugin - new Realm.BSON.ObjectId() is invoked twice for property initialization #5140

Closed
takameyer opened this issue Nov 25, 2022 · 0 comments · Fixed by #5155
Closed

Comments

@takameyer
Copy link
Contributor

takameyer commented Nov 25, 2022

How frequently does the bug occur?

All the time

Description

Give the following class:

export class Task extends Realm.Object<Task> {
  _id: Realm.BSON.ObjectId = new Realm.BSON.ObjectId();
  description!: string;
  isComplete: boolean = false;
  createdAt: Date = new Date();
  userId!: string;

  static primaryKey = '_id';
}

When two objects are created using:

realm.write(() => {
  return new Task(realm, description, userId);
});

The resulting _id is two increments higher between the first and the second item. Oddly enough, when using sync and Atlas, the _id is on increment smaller for the created items. This causes various issues when trying to make modifications when permissions are set.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

This bug exists in the current example application in realm.

  • Setup App Service and get the AppId
    • Enable username/password login
    • Enable Flexible Sync
      • Add userId to the queryable fields
      • Create a permissions object:
{
 "rules": {},
 "defaultRoles": [
   {
     "name": "owner-read-write",
     "applyWhen": {},
     "read": {
       "userId": "%%user.id"
     },
     "write": {
       "userId": "%%user.id"
     }
   }
 ]
}
  • Configure the sync.config.js in the example app with the AppId
  • Run the example application
    • Create a new user
    • Create a few items
    • Check the "done" checkbox

The Items will disappear

Version

11 and above

What SDK flavour are you using?

Atlas App Services (auth, functions, etc.)

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Platform Independent

Build environment

Which debugger for React Native: ..
None

Cocoapods version

Irrelevant

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
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