Data: Setting async belongsTo not working after previous fetch rejected

Created on 6 Dec 2019  ยท  7Comments  ยท  Source: emberjs/data

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: https://github.com/emberjs/data/pull/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]
Bug unload-apis

Most helpful comment

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

All 7 comments

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.

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

@runspired - Here you go: https://github.com/emberjs/data/pull/6874

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: ฦ’}

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

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

@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.

Was this page helpful?
0 / 5 - 0 ratings