-
-
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
add test + fix for chained async has many #7691
Conversation
@@ -848,7 +848,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( | |||
}); | |||
}); | |||
|
|||
test('A hasMany relationship can be reloaded if it was fetched via a link', function (assert) { | |||
test('A hasMany relationship can be reloaded if it was fetched via a link', async function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the noise, this one was just a refactor, getting rid of run().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No apology necessary, thanks a bunch for the cleanup?
@Turbo87 At least the "fix" seem to make crates.io's tests happy ;) |
let adapter = store.adapterFor('application'); | ||
|
||
store.modelFor('user').reopen({ | ||
messages: hasMany('message', { polymorphic: true, async: true }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we use polymorphic: true
here? at least in crates.io we don't seem to have any polymorphic relationships 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just because this is how the relation is defined at the top of the file. (
messages: hasMany('message', { polymorphic: true, async: false }), |
I wanted to use the 'same' relation, but async.
@runspired this looks like the correct fix to me, as if you push the same record twice, the deleted branch of code marks the link as not stale so it does not get fetched, even though it had never been fetched. What are your thoughts |
@igorT Thanks again for looking into it. I've added an assertion to complete the tests (after @runspired pointed me that the state of the hasMany's promise looks not good). |
c713916
to
d328ef5
Compare
As I failed to make the test pass, I tried to make more debugging, to see what happen. I think there are subtle bugs on how the hasMany() computed property is cached/invalidated. For example, considering this code at the end of the added test in
and the "fix" (don't set isStale to false), gives this result: See how the PromiseManyArray state is reset to not fulfilled just because we call again the cc/ @igorT |
@igorT any news on this? I've just hit the same issue in another project too 😅 |
We've ran into the issue as well and rolled back to 3.27 for now. If there's anything I can do to help with fixing this, please let me know. |
@benedikt Same here about sticking with 3.27.
I would say, if you find how to make the tests pass in this PR, it could be a potential fix for the issue. I really don't know what to do :( |
}); | ||
|
||
let comments = await post.get('comments'); | ||
assert.ok(post.comments.isFulfilled, 'comments promise is fulfilled'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like post.comments
will trigger an update of the promise proxy. That's why this assertion fails. Removing that proxy update fixes this particular test, but obviously breaks a few others.
I guess the question is what we expect to get from consecutive post.comments
calls. Are they supposed to return the cached results or do they all trigger a new fetch?
As the relationship is marked as async, I guess the behavior is correct? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said in a previous comment I don't know how consecutive calls of post.comments
should behave :(. And it looks like that calling post.comments
won't always trig the update you mentioned (since DS.hasMany() is a computed property).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have read all the comments before diving into the code 😬 🙈
Looks like the computed property gets invalidated while loading the data for the first time in the replace related record operation which eventually calls The first call loads the data, which changes the state, which invalidates the property. The second time (probably?) also loads the data, but the state doesn't change (because it's the same data) and therefore doesn't invalidate the property. I don't have a solution, but hopefully that explains why the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with the proposed deletion of the isStale = false state update branch
@runspired In that case I must remove these checks https://github.com/emberjs/data/pull/7691/files#diff-e129eb0fe00707712a6ceb0f1fc5abbd5b0a90fdd95281f0923d8904ff39abd8R1335 from the tests, because they fail |
@sly7-7 I don't think you need to remove the checks. Does need to be investigated as to why it fails, seems the promiseArray is unstable which it likely shouldn't be. |
@snewcomer Well, for me it's complicated. I think async relationships are somewhat broken since 3.28 (you can see #7684 and also issues linked to this one). With this change, the issue seemed to be fixed, but at the same time it surfaces an other one, where the state of the underlying promise is unstable (eg, calling twice |
3f5771b
to
78c6769
Compare
ca4bee4
to
8319aad
Compare
* [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]>
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]> Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
* Backport Train for Beta (#7803) * deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]> * fix Co-authored-by: Chris Thoburn <[email protected]> Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
@@ -902,11 +903,18 @@ export default class InternalModel { | |||
|
|||
notifyHasManyChange(key: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much @runspired. I would never have guessed the culprit was here. I don't know how you found that. All look so easy for you 😅
* [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]>
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
* Backport Train for Beta (#7803) * deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]> * fix lint * fix ie11 Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
cc/ @Turbo87 Could you confirm your scenario is the same as this one ?
resolves #7684 (at least the mentioned test suite passes locally)