Duplication in this.store when creating a record on a route using RealtimeRouteMixin
See original GitHub issueVersion info
index.js:185 DEBUG: Ember : 3.10.2
index.js:185 DEBUG: Ember Data : 3.10.0
index.js:185 DEBUG: jQuery : 3.4.1
index.js:185 DEBUG: EmberFire : 3.0.0-rc.3
index.js:185 DEBUG: Firebase : 6.2.2
index.js:185 DEBUG: -------------------------------
When creating and saving a Firestore Record on a route using RealtimeRouteMixin the following error occurs Uncaught (in promise) Error: Assertion Failed: 'nameOfModel' was saved to the server, but the response returned the new id 'HYplP17VdPrSjDwZd8Ig', which has already been used with another record.'
A single copy of the record is correctly saved to Firestore, but the local store contains two copies of it; One copy has the correct Firestore value for its id
, the other copy has null
for its id
and the following unsaved indicators {isDirty:true, isSaving:true hasDirtyAttributes:true dirtyTYpe: "created"}
The error and duplication in the store do not occur if the RealtimeRouteMixin is removed form the route.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Duplication in this.store when creating a record on a route ...
When creating and saving a Firestore Record on a route using RealtimeRouteMixin the following error occurs Uncaught (in promise) Error: ...
Read more >Duplicate null-id records in ember-data - Stack Overflow
I'm using ember 1.0 and ember-data 1.0.0 beta 1. I have the following routes and controller to create and save simple notes ('AuthenticatedRoute'...
Read more >Creating, Updating and Deleting - Ember Data
Creating Records You can create records by calling the createRecord() method ... The store object is available in controllers and routes using this.store...
Read more >business rule creating duplicate record in original table
Solved: Ok so I have a business rule that does what it should, it creates a new song record in a 'set list'...
Read more >NetSuite Applications Suite - Duplicate Detection Preferences
Set Up Duplicate Detection page. For each type of record, in the Fields to Match On box, select the fields from respective record...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After some more digging around…
The realtime duplication issue that occurs when
store.createRecord
(+save) and realtime-listeners’store.push
manage the same record simultaneously, is due to the way ember-data manages identity of records without an id. Whenstore.createRecord
is not supplied an id, it begins by creating aclientId
to manage identity. When aclientId
is present, the callStack for bothstore.createRecord
andstore.push
change; that change creates the identity problem that results in the duplication issue.ember-data is preparing to update its internal Identifiers and it probably makes sense to participate in that rfc’s maturity. Without updates to ember-data the simplest way to avoid the realtime duplication issue is to avoid ember-data’s use of clientId by supplying an id for createRecord, or by disabling the realtime subscription during createRecord.
Disabling the routes realtime subscription during createRecord
In the route
route.setupController
is used to place an instance of the route on the controller. The realtime-listener uses that instance to identify the subscription.In the controller
store.createRecord
is insulated from the realtime-listener with an unsubscribe/subscribe pair.Suppling a local uuid for createRecord
store.createRecord
gives the adpater a chance to provide a local id for a new record withgenerateIdForRecord
I tried using that function to await an id from Firebase but
store.coerceId
ended up stringifying the promise. Intefering with ember-data’s backburner queues seems dangerous… The docs forgenerateIdForRecord
recommend usingdidCommit
for a server generated id but is too late in the cycle to avoid the identity failure.Supplying a firebase id for createRecord
Since
adapter.generateIdForRecord
is too late in the stack to request a firebase id, a service is used to generate the key and await that key increateRecord
.In the controller…
I would not count this as resolved, but perhaps these solutions will be helpful to others.
rc.4 shipped.