Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-362

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

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      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

            Assignee:
            linnea.jansson@mongodb.com Linnea Enoh Jansson (Inactive)
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: