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

Setting async belongsTo not working after previous fetch rejected #6867

Closed
danwenzel opened this issue Dec 6, 2019 · 7 comments · Fixed by #7554
Closed

Setting async belongsTo not working after previous fetch rejected #6867

danwenzel opened this issue Dec 6, 2019 · 7 comments · Fixed by #7554
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@danwenzel
Copy link

Description

Starting with ember-data version 3.12.0, setting a belongsTo relationship property on a model is not working after that relationship previously rejected. As an example, if an async fetch of a post's user returns a 404, I'm then catching the error, creating a new user, and setting it to the post:

async fetchOrCreateUser() {
  try {
    await this.post.get('user');
  } catch (error) {
    // 404 returned.  Create a new user and set it as the post's user
    const newUser = this.store.createRecord('user', {
      name: 'Larry',
    });
    this.post.set('user', newUser);
  }
},

Expected

this.post.user is now the new user

Actual

this.post.user continues to be the rejected promise from the first get

I'm pretty sure this has to do with this change: #6112

This issue does not occur in version 3.11.5 and below.

Reproduction - Failing Case (v3.12.0)

Notice that the user name never populates, and isRejected is always true

Reproduction - Non-failing Case (v3.11.5)

Notice that the user name does populate successfully

Versions - Failing Case

yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
✨  Done in 0.62s.
yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
✨  Done in 0.63s.
yarn list v1.19.1
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
└─ [email protected]

Versions - Non-failing Case

yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
✨  Done in 0.67s.
yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
✨  Done in 0.61s.
yarn list v1.19.1
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
└─ [email protected]
@runspired
Copy link
Contributor

Thanks! If you have time to turn your reproduction into a test scenario that would be awesome, but regardless thanks for the report.

cc @code0100fun let's roll this into the unload work since it's a similar issue to what you started out working on.

@danwenzel
Copy link
Author

Hi, @runspired, thanks for your response! Yeah, I'll try to get a test scenario written early this week

@danwenzel
Copy link
Author

@runspired - Here you go: #6874

@veelenga
Copy link

veelenga commented Jan 3, 2020

Also faced with this issue during the upgrade to 3.12. I assume this behaviour is related:

> record.set('myRelation', null)
null
> record.myRelation
Proxy {isFulfilled: false, isRejected: false, content: null, _belongsToState: {}, _super: ƒ}

@runspired
Copy link
Contributor

@veelenga your example above seems like correct behavior, content is null

@danwenzel
Copy link
Author

Hey there @runspired and @code0100fun . Just checking to see if there is an ETA on this one yet

@kiwiupover
Copy link

@runspired G'day mate is there any movement here. Or is there a better way for us to move forward?

I loved the sit ups and your dog video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants