data
data copied to clipboard
hasMany relationship loses its records if they fail to load
Twiddle: https://ember-twiddle.com/8be9daa561c3b5fd9b6c
My research so far indicates the following:
- When a record has failed to load, it will be unloaded from the store. This causes it to be removed from the relationships, which have a reference to it.
- Although the records are still available in the relationship canonical state, this doesn't help much. Both
parent.save()
andparent.get('children').reload()
considers the relationships to be empty.
The above behavior is making it harder to handle errors loading hasMany collections, because only the first request to parent.get('children')
will return a PromiseManyArray
, which will be rejected (supposedly). Subsequent requests will just return successfully resolved empty PromiseManyArray
. This means that it is essential that the very first instance is saved somewhere and propagated to the rest of the app.
An expected behavior would be to have the parent.get('children')
return the same PromiseManyArray until reload()
is called. This would allow anyone to get the current state of the affairs. This is how it is supposed to work, because of Ember.computed
cached value, but it is invalidated when the problematic record is unloaded.
The PromiseManyArray
here is stable, I think the underlying issue was that the state of the backing array changes. I doubt this is still an issue today for an async relationship as the unloaded record would still be in the membership for the reload with how we do things, but we should add a test before closing this ticket.
I recently spent time on this set of load-failure behaviors when making some of our unsupported emergent behaviors more recoverable (see #8846 and associated tickets). In doing so I've realized the original ask is not something we could ever support.
If an API fails to load a record, regardless of the reason, it needs to be removed from relationships until there is a successful payload containing that information.
What this means is that relationships that are expected to potentially fail need to be based on links instead of identity, which is a mode that is extremely well supported here.