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

null model is stored in cache #4346

Closed
trevorrjohn opened this issue Apr 20, 2016 · 2 comments
Closed

null model is stored in cache #4346

trevorrjohn opened this issue Apr 20, 2016 · 2 comments

Comments

@trevorrjohn
Copy link
Contributor

So I am encountering this issue when using DS.RESTAdapter and getting an empty JSON object response when calling DS.Model#save(). The API returns an empty object and as expected nothing is stored in the store. However this happens:

DS.Store#findAll('user').get('length') // => 0 (good)
DS.Store#peekAll('user').get('length') // => 1 (bad)

The desired outcome would be for both to evaluate to 0.

When I inspect on the object stored in the cache, every field is null. So even calling unclearRecord does not work. Calling unclearAll('user') does actually remove the cached object, but I don't think this should ever get into this state. I think peekAll should return no objects or there should be an error thrown when the adapter tries to parse a response with no id.

I created an example project that shows the behavior: https://github.com/trevorrjohn/bad-cached-data

Thanks!

@pangratz
Copy link
Member

store.peekAll returns is a live updating array with all records in the store, which also includes new records which are not yet saved. So I think store.peekAll() is working as expected here.


I am wondering though why there is no assertion for save() returning no data, because this will result in a record having isLoaded === true but isNew === false and id === undefined, as shown in this ember-twiddle.

@trevorrjohn
Copy link
Contributor Author

Yes, @pangratz narrows down the issue better than my example.

bmac added a commit to bmac/data that referenced this issue May 27, 2016
…d and the id was not already provided by the client

Closes emberjs#4346
runspired pushed a commit to runspired/data that referenced this issue Oct 17, 2016
…d and the id was not already provided by the client

Closes emberjs#4346
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

No branches or pull requests

2 participants