data icon indicating copy to clipboard operation
data copied to clipboard

Strange behavior of the store sins 3.28.0 or later

Open Timbuktu1982 opened this issue 4 years ago • 10 comments

Hi. I have a lot of similar and curiously problems, since we used [email protected]. I can't say for sure that we've had the problems since 3.28.0 or later. I'll try to summarize two problems of them briefly here. If you think its better to post a new issue, please let me know.

First problem: I get records from backend by using query to get data for model "test" with filter=xxx and include=a,b,c and the backend delivers the correct entries. Now i get a record of one of this (with findRecord and reload:true) and change a property (attribute) of this entry (without saving the model). Then i do a new query for model "test" with same filter and same include. Now the store should actually replace the changed entry with the reloaded entry (like before 3.28.x). The store ignores the responsed data and do not override/reset the change property.

Only when i do a unloadAll("test") before the second request, the store uses responsed data and overrides. But when i do the complete process of first problem again (after unloadAll), the unloadAll has no effect and the store ignores every new requests/responses.

Second problem: I do the same like first problem. But i additional change a belongsTo-relation from null (unused) to a specific relationship. When i do a query or a findRecord (with reload) again, the belongstTo-relation has the changed specific relationship and not null. The store ignores the new requests and responsed data. unloadAll or unloadRecord has no positive effects. This problem concerns only relations, they not set (null).

When i change a relation from one saved specific realationship to another, the store overrides the relations by using responded data. In this case the unloadAll or unloadRecord has positive effects and resets relation to origin relationship.

The adapter methods (shouldBackgroundReloadAll, shouldBackgroundReloadRecord, shouldReloadAll, shouldReloadRecord) to force reloading have no positive effects.

I think its a important bug - the behavior before 3.28.x was another (and correct working for my opinion).

We need help, very urgent.

Originally posted by @Timbuktu1982 in https://github.com/emberjs/data/issues/7688#issuecomment-948309919

ember-data: 3.28.3 ember: 3.28.1 all packages are up to date.

Timbuktu1982 avatar Oct 23 '21 04:10 Timbuktu1982

Additional problem discovered: In rare cases I have the problem that the isDirty state (after findRecord with reload:true) is reset correctly, but a previously made change to a relation (which at this moment has no relationship yet) still contains the changed value instead of having been reset correctly.

Description:

  1. Load a model with findRecord.
  2. Change a relation X (which at this moment has no relationship yet) of this model to a specific relationship.
  3. isDirty => true
  4. Reload this model with findRecord and reload:true.
  5. isDirty => false
  6. Relation X has the same selected relationship like 2.

Timbuktu1982 avatar Oct 25 '21 06:10 Timbuktu1982

I'm guessing it could be one of these two:

  • https://github.com/emberjs/data/issues/7688
  • https://github.com/emberjs/data/issues/7684

sandstrom avatar Nov 16 '21 07:11 sandstrom

Honestly this mostly just sounds like you just noticed how ember-data has always worked. It may be that before you were rolling back the dirty state and now you are not, but by default ember-data has always preserved dirty attribute state and additions of new records to relationships when fresh data is loaded / a record is reloaded.

Also, since relationships have never affected dirty state, I'm curious whether you maybe are using an addon that is attempting to change how ember-data works / used private APIs and has potentially broken against 3.28+?

runspired avatar Dec 14 '21 10:12 runspired

@Timbuktu1982 Can you try with 3.28.8 and see if the problem persists? (the two issues mentioned above have been fixed in that release, either of which may solve your problem)

sandstrom avatar Jan 03 '22 16:01 sandstrom

Yeah, i will test in the next days and give you response whether it works or fails again...

Timbuktu1982 avatar Jun 23 '22 10:06 Timbuktu1982

@Timbuktu1982 any word?

runspired avatar Aug 12 '22 09:08 runspired

@runspired Awesome work on Ember Data lately, have you considered adding a $200 sponsoring tier? 😄

sandstrom avatar Aug 12 '22 11:08 sandstrom

Sorry, I haven't had a chance to test this further yet. I'll put it on my agenda for the next few days. I'll be in touch. Thanks in advance

Timbuktu1982 avatar Aug 12 '22 11:08 Timbuktu1982

@sandstrom added

runspired avatar Aug 12 '22 20:08 runspired

@runspired Tier updated! 😄

sandstrom avatar Aug 13 '22 15:08 sandstrom

closing, happy to revisit if there still turns out to be something to resolve

runspired avatar Apr 07 '23 23:04 runspired