-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
failed test: createRecord creates two records on ember 3.0 #5359
Conversation
I also see a deprecation error on this line which doesn't seem right user.get('messages.firstObject')
// Getting the '@each' property on object <DS.Errors:ember9921> is deprecated |
So after some initial sleuthing, that same call stack appears when using Ember 2.11 as well. It's not clear to me why two records are created. |
@mmun Thanks for looking into this. Sure enough, I see the same reentrant call into |
@dwickern I'll keep looking later today. |
So I've got an update. I haven't been able to do a full root cause as it is simply too complicated for me and I don't have the time to step through it at all. However, what I can say is that it looks like a messy interaction between array events being triggered during initialization (i.e. before It's not obvious to me whether this is a bug in the current object model or simply a known limitation. I'll ask Kris later. Fortunately, we can avoid this issue relatively easily by changing data/addon/-private/system/store.js Line 361 in 1732cd5
let record = internalModel.getRecord();
setProperties(record, properties); This will allow the record to be fully instantiated and assigned into the internal model's A couple implementation notes: 1) we probably want to remove the properties parameter entirely for getRecord. 2) with my proposed implementation we end up assigning |
Here are some issues where this behaviour was initially introduced:
I believe it is acceptable to revert that PR until it can be implemented correctly (i.e. not creating two records recursively). I think it would also be fine if someone wants to attempt to fix the current implementation. |
I bisected the ember.js commit down to what I expected it to be: emberjs/ember.js#16166. Still, I'm not sure whether this is more of Ember or Ember data's fault, since the trivial refactor of moving the property assignments described in #5359 (comment) to avoid the double create fixes the issue in emberjs/ember.js#16258 as well. |
The fix from #5359 (comment) LGTM, I'll open a PR unless you want to look into it further |
@dwickern I am worried that, while the fix I described will correctly fix this bug, it is undoing something that was done intentionally to solve #4509. I believe it ought to be possible to fix this bug without compromising but I haven't been able to figure it out yet. I've pinged some other core team members to take a look. If we can't get to the bottom of it in the next couple weeks than I think we'll have to do the fix I described. |
After upgrading ember from 2.18.2 to 3.0, with ember-data unchanged at version 2.18.1, a call to
createRecord
creates 2 records.It happens under these conditions:
createRecord
sets up a relationship which has an inverseHere's a shortened example of the problem:
It works if you set up the relationship after construction:
It also works if nobody is observing the
comments
array.The stack trace explains why:
createRecord
updates the inverse record array synchronously before actually creating the record