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.

Records created with a previously deleted ID generates an uncaught error

See original GitHub issue

In my application, I have what I think is a fairly standard User model, whose IDs are based on the authenticated users’ fbRef.getAuth().uid value (which in my case is assigned by the Anonymous authentication provider). I have a global users which dynamically updates as users authenticate/unauthenticate, that is populated using a basic this.store.find('user') call.

The problem arises when a user signs out, and then re-authenticates/signs in with the same auth uid. I recieve the following error in the consoles of the other currently connected browsers:

Uncaught Error: Attempted to handle event pushedData on <myapp@model:user::ember938:anonymous:-JZ51lM7UkJUuD6pp9Yw> while in state root.deleted.uncommitted.

(note however, that the user/browser that did the signing out/re-logging in receives no error)

Is there anything else I need to do in this scenario to make sure that records automatically deleted by emberfire are fully committed in each connected client’s cached store, or is this a limitation of some sort?

For reference, here is how I am creating the records when a user signs in:

var user = this.store.createRecord('user', {
    id: fbRef.getAuth().uid,
    nickname: nickname,
    joinedAt: new Date()
});

user.save();

And when they sign out:

this.store.find('user', fbRef.getAuth().uid).then(function(user) {
    user.destroyRecord();
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
tstirratcommented, Apr 3, 2015

I can confirm this, a record removed on the server will also remove locally, but the deleted record will still be cached locally in the store. This is because we use model.deleteRecord instead of model.destroyRecord here.

On the client that deletes the record, as long as you use destroyRecord it is usually ok:

post.get('id'); // -Jm0LzWtETCIw-LT9ZUP
post.destroyRecord().then(function () {
  store.recordForId('user', '-Jm0LzWtETCIw-LT9ZUP'); // undefined
});

But on a different client that observed the delete from the server, the deleted record is still there:

// -Jm0LzWtETCIw-LT9ZUP was deleted on server
store.recordForId('user', '-Jm0LzWtETCIw-LT9ZUP'); // returns the deleted (hidden) record

store.createRecord('user', { id: '-Jm0LzWtETCIw-LT9ZUP', ... });
// Assertion Failed: The id -Jm0LzWtETCIw-LT9ZUP has already been used with another record of type dummy@model:user:.

The workaround is to find the record and unload it manually before creating:

store.recordForId('user', '-Jm0LzWtETCIw-LT9ZUP').unloadRecord();
store.createRecord('user', { id: '-Jm0LzWtETCIw-LT9ZUP', ... }); // works
0reactions
gabrielgrantcommented, Jun 10, 2016

I’m inclined to say that using only unloadRecord is best: if a record has been edited locally before being deleted by another client, that is a legitimate data conflict that should raise an error to allow the client-side code to handle it gracefully (eg. alerting the user that the record has been deleted on the server, and asking if they want to re-create it using their local data, or just lose their changes)

The one potential issue, as raised in #322, is that afaik just calling unloadRecord will not fire the record’s didDelete event. That being said, I’m not convinced the didDelete event should fire – there’s a clear difference between a record being deleted locally vs receiving an update from the server. But if the event is desired, then it could just be triggered manually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to re-create a deleted record (same ID) #5014 - GitHub
I have a record with ID is sample_account. I have deleted it by using this code: record.destroyRecord(); But when I re-create a new...
Read more >
"entity is deleted" error if changes exported to Salesforce after ...
If you delete a Salesforce record that was exported from Drupal, and then you try to export changes from Drupal to Salesforce, ...
Read more >
Reusing Ids For Soft Deleted Records - Ember Data
I am seeing the error above when I delete a record (soft delete), and then recreate the record. The record is being reactivated...
Read more >
Cannot delete or update a parent row: a foreign key constraint ...
You get this error because the user you would like to delete has associated records within the appointments table. You have 2 options:....
Read more >
Salesforce Error: Create/Update OBJECT - entity is deleted
If you are receiving this error, it means that one of the record IDs being mapped in your connector is the ID of...
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