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

[BUGFIX] Fix issues with links #5257

Closed
wants to merge 9 commits into from

Conversation

BryanCrotaz
Copy link
Contributor

@BryanCrotaz BryanCrotaz commented Nov 12, 2017

Fix issue #5209 and #5211

when one end of a relationship is marked {inverse:null} keep the two relationships separate in the cache and don't create the ":" cache entry

minor optimisation in relationship-payloads.js - don't scan an array multiple times

In RelationshipPayloads, don't overwrite an inverse relationship if it's got links instead of data

Fixup nested relationships test which now needs to download its links

This should be backported to 2.14,15,16

BryanCrotaz and others added 6 commits November 12, 2017 02:20
when one end of a relationship is marked {inverse:null} keep the two relationships separate in the cache
minor optimisation too
Don't overwrite links in cached payload when populating the other side of a relationship
@ppcano
Copy link
Contributor

ppcano commented Nov 13, 2017

This fixes #5235 (initially reported in #5219). This bug is blocking our ED upgrade.

@BryanCrotaz Thanks a lot; feel free to include the #5235 failing test.

@sly7-7
Copy link
Contributor

sly7-7 commented Nov 17, 2017

@bmac @hjdivad :shipit: ?

}
}
})
}, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip the new Promise/run.later(..., 10) and simplify this method with just return Promise.resolve(...)

return Promise.resolve({
        data: {
          id,
          type: 'user',
          relationships: {
            organisation: {
              data: { id: 1, type: 'organisation' }
            }
          }
        }
      });

}
}
})
}, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

} else {
resolve({ data: [] });
}
}, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same story here. Returning Promise.resolve(...) in each branch of this conditional should allow us to remove the run.later.

@bmac
Copy link
Member

bmac commented Nov 19, 2017

Overall this change looks good. I just had a few comments for some cleanup in the tests.

@BryanCrotaz
Copy link
Contributor Author

@bmac changes made

}
return resolve({ data });
}
}));
Copy link
Member

@pangratz pangratz Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this approach for fixing the failing test, as it seems this introduces a change in the semantics: before no link was fetched, now it is when we get the kids relationship on line 138/153:

assert.ok(middleAger.get('kids').includes(kid));

This essentially boils down to if a relationship should be considered loaded when link & data is provided 😔 .

For this PR it might be best to change the assertion so we check the content of the relationship in a side-effect free way:

assert.ok(middleAger.hasMany('kids').value().includes(kid));

this._cache[lhsKey] = newRelationship;
if (rhsKey && !this._cache[rhsKey]) {
this._cache[rhsKey] = newRelationship;
}
Copy link
Member

@pangratz pangratz Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the comment above the code outdated, as we are not always populating the cache with the same payload. It might makes sense to update the comment to reflect that...

@pangratz
Copy link
Member

pangratz commented Dec 4, 2017

@hjdivad @runspired would you have time to take a look at these changes?

@runspired
Copy link
Contributor

@pangratz I don't think this is necessary if we fix the inverse bug but I'll reconfirm.

@mattraydub
Copy link

Any idea why this hasn't been merged/accepted yet?

@runspired
Copy link
Contributor

Mostly it's the wrong fix.

@mattraydub
Copy link

thanks @runspired . Is there a valid fix elsewhere? Or is it still being considered / worked on. I had cherry picked this commit into the production version of ember-data we are using, and its been working fine, however I'd prefer to stay in line with what is going to get released.

@runspired
Copy link
Contributor

@mattraydub yes, #5230

@bmac
Copy link
Member

bmac commented Mar 5, 2018

@BryanCrotaz has #5230 resolved this issue?

@BryanCrotaz
Copy link
Contributor Author

BryanCrotaz commented Mar 6, 2018

@bmac In lockdown at the moment for a big complex release of 8 interrelated Ember apps, but when that horror show is complete I'll upgrade to #5230

@pangratz
Copy link
Member

@bmac AFAICT the fix in #5230 hasn't addressed the issues with links, which this PR is solving...

@BryanCrotaz
Copy link
Contributor Author

Haven’t hadn’t a chance to test it yet

@runspired
Copy link
Contributor

@pangratz there may be a separate issue but I dug in months ago and it most definitely did resolve this.

@pangratz
Copy link
Member

I ran the test from #5235 against latest master and it's still failing (because the relationship payload is overwritten here and the links are thrown out).

@runspired
Copy link
Contributor

@pangratz that test is wrong. Neither side specifies inverse: null. Does it still fail if you fix the test? Overwriting in the non null case is the expected behavior.

@runspired
Copy link
Contributor

Also cc @hjdivad, I suspect we could do a nicer thing here and merge links so as to keep both unless links is explicitly overwritten by the API

@pangratz
Copy link
Member

@runspired uh la la. I can confirm that inverse: null fixes the failing test in #5235.

@sly7-7
Copy link
Contributor

sly7-7 commented Mar 12, 2018

It's not clear to me why we must add inverse: null in the test, could someone explain that to me please?

@runspired
Copy link
Contributor

@sly7-7 if you do not specify inverse null, then we auto-resolve the other side of the relationship to create a link between the two classes. This results in either side being able to set the state of the relationship, which the test is asking us to not do.

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

Successfully merging this pull request may close these issues.

7 participants