question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The Realm is already in a write transaction

See original GitHub issue

I’m getting an error when writing to a Realm db. I’ve looked at other solutions for this, and the recommended approach to checking if in a write transaction doesn’t seem to be available in Realm JS. Is there some other mechanism to address this? Thanks!

Here’s the offending code:

addAll: Function = (businessesToAdd): ?Array<Business> => {
    let businesses: Array<Business> = [];

    Realm.write(() => {
      businesses = businessesToAdd.map(business => {
        return Realm.create(ClassName, { ...business }, true);
      });
    });

    return businesses;
  };
ExceptionsManager.js:71 Error: The Realm is already in a write transaction
    at sendRequest (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:130302:7)
    at Object.callMethod (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:130220:1784)
    at Realm.<anonymous> (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:130063:771)
    at BusinessDAO.exports.BusinessDAO.addAll (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:137351:17)
    at _callee$ (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:137464:23)
    at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:26695:29)
    at Generator.invoke [as _invoke] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:26969:12)
    at Generator.prototype.(anonymous function) [as next] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:26728:13)
    at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:26695:29)
    at invoke (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:26771:12)

screenshot_20170628-132030

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bhaskarmurthycommented, Jul 4, 2017

@blagoev As a followup, we do not have any nested .write blocks, and it doesn’t seem like the issue is fixed as per #127 .

Are there any steps we can take to debug into this a bit more?

0reactions
knethcommented, Aug 29, 2017

We have added manual transactions to help in this situation. I hope we can release it this week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

the realm is already in a write transaction - Stack Overflow
The rule of thumb for Realm is only one write transaction open on an RLMRealm at any given time.
Read more >
Realm is already in write transaction · Issue #6215 - GitHub
I am using below method to write in DB, but sometimes getting random issue "The Realm is already in a write transaction in ......
Read more >
Already in write transaction at stress test - Realm - MongoDB
I'm confuse with a behaviour im observing at realm (swift). So from beginning, I got this error. Fatal error: 'try!' expression unexpectedly ...
Read more >
[Fixed]-the realm is already in a write transaction-objective-c
The rule of thumb for Realm is only one write transaction open on an RLMRealm at any given time. You might need to...
Read more >
Objective-c – the realm is already in a write transaction
How can i avoid this error? is there a way to check realm is in write traction? if realm is in write transaction...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found