Skip to content
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

Error for async hasMany and store.unloadAll #5063

Closed
shamcode opened this issue Jul 13, 2017 · 4 comments
Closed

Error for async hasMany and store.unloadAll #5063

shamcode opened this issue Jul 13, 2017 · 4 comments

Comments

@shamcode
Copy link

Hi!
I have two models:

//models/foo.js
export default Model.extend({
  bars: hasMany('bar', {async: true})
});

//models/bar
export default DS.Model.extend({});

Sample response for store.findAll('foo') (pay attention to links):

{
  "data": {
   "id": 1,
   "type": "foo",
   "relationships": {
     "bars": {
       "links": { "related": "bars" }
     }
   }
}

And then i try load relationships with code:

// routes/application.js
export default Ember.Route.extend({
  model() {
    return this.store
      .findRecord('foo', 1).then((foo) => foo.get('bars'))
      .then(() => {
        this.store.unloadAll('foo'); // If comment this row, tests pass
        return this.store.findRecord('foo', 1).then((foo) => foo.get('bars'))
      });
  }
});

Ember throw error

Error while processing route: index Assertion Failed: calling set on destroyed object: <DS.PromiseManyArray:ember257>.content = <DS.ManyArray:ember258> Error
    at Object.assert (http://localhost:4200/assets/vendor.js:24286:15)
    at set (http://localhost:4200/assets/vendor.js:35785:45)
    at Class.set (http://localhost:4200/assets/vendor.js:49787:34)
    at ManyRelationship._updateLoadingPromise (http://localhost:4200/assets/vendor.js:161232:31)
    at ManyRelationship.getRecords (http://localhost:4200/assets/vendor.js:161451:19)
    at Class.get (http://localhost:4200/assets/vendor.js:169637:58)
    at ComputedPropertyPrototype.get (http://localhost:4200/assets/vendor.js:36390:28)
    at get (http://localhost:4200/assets/vendor.js:35698:19)
    at Class.get (http://localhost:4200/assets/vendor.js:49721:34)
    at http://localhost:4200/assets/ember-data-async-has-many-after-unload-bug.js:394:22

Repo for reproduce (just run acceptance test)
Collected ember-try report:

------ RESULTS ------

Scenario ember-data 2.15.0-beta.2: FAIL
Command run: ember test
┌────────────────────┬────────────────────┬──────────────────────────────┬──────────┐
│ Dependency         │ Expected           │ Used                         │ Type     │
├────────────────────┼────────────────────┼──────────────────────────────┼──────────┤
│ ember-data         │ 2.15.0-beta.2      │ 2.15.0-beta.2                │ npm      │
└────────────────────┴────────────────────┴──────────────────────────────┴──────────┘

Scenario ember-data 2.14.4: FAIL
Command run: ember test
┌────────────────────┬────────────────────┬──────────────────────────────┬──────────┐
│ Dependency         │ Expected           │ Used                         │ Type     │
├────────────────────┼────────────────────┼──────────────────────────────┼──────────┤
│ ember-data         │ 2.14.4             │ 2.14.4                       │ npm      │
└────────────────────┴────────────────────┴──────────────────────────────┴──────────┘

Scenario ember-data 2.13.2: FAIL
Command run: ember test
┌────────────────────┬────────────────────┬──────────────────────────────┬──────────┐
│ Dependency         │ Expected           │ Used                         │ Type     │
├────────────────────┼────────────────────┼──────────────────────────────┼──────────┤
│ ember-data         │ 2.13.2             │ 2.13.2                       │ npm      │
└────────────────────┴────────────────────┴──────────────────────────────┴──────────┘

Scenario ember-data 2.12.2: SUCCESS
Command run: ember test
┌────────────────────┬────────────────────┬──────────────────────────────┬──────────┐
│ Dependency         │ Expected           │ Used                         │ Type     │
├────────────────────┼────────────────────┼──────────────────────────────┼──────────┤
│ ember-data         │ 2.12.2             │ 2.12.2                       │ npm      │
└────────────────────┴────────────────────┴──────────────────────────────┴──────────┘


3 scenarios failed
1 scenarios succeeded
4 scenarios run

If i don't use links for hasMany, all work perfectly: ember-twiddle

@stefanpenner
Copy link
Member

stefanpenner commented Jul 13, 2017

Thanks. I think this is related to some of the recent model resurrection stuff that was recently added. We have been working to tidy it up, I will make sure this case is added to the scenarios that are problematic.

If you have some cycles, submitting a pull request with a failing test would be very helpful.

shamcode added a commit to shamcode/data that referenced this issue Jul 17, 2017
@shamcode
Copy link
Author

shamcode commented Jul 17, 2017

@stefanpenner I've add tests for this behavior, but I think they aren't clear. Test contains override for method _ajaxRequest with setTimeout. I think, jQuery use this function for AJAX
Should I fix this and do not use setTimeout?

@shamcode
Copy link
Author

Related issue #4986

@runspired
Copy link
Contributor

I believe this is resolved as of #5378. Please feel free to re-open if you find this is still a bug on the latest master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants