-
-
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
Request a nonexistent data by id still push to the store using RestfulAdapter #1931
Comments
What behavior would you expect? |
@luthur Seems related to my problem (and other problems related to that): @tomdale Expected behavior should be that there is a proper error handling mechanism for not found errors (error thrown or some hook to handle this) and Ember-Data should not create any empty zombie records automatically. |
@jaaksarv Is the record not going into an |
@tomdale at least I can handle that error and the wrong undefined data should not be pushed into store |
@tomdale My case is that API (that is not under my control) returns empty response instead of 404. I can still detect when record is not found, but there is no public API for solving the this case. I use record.send('unloadRecord'); to fix it, but this solution has some side-effects. My main concern is not directly loading the record but abandoned belongsTo relationships that will create zombie records that will hang around and show up in lists. |
Maybe I am misunderstanding the behavior here, but it sounds like it's working as intended. My view is that errored records absolutely should be pushed into the store—if you request a @jaaksarv It sounds like there's a secondary issue here, which is that errored records are showing up in queries. If that's happening, please file a separate issue describing what you're seeing. |
@tomdale suppose you request |
@luthur It sounds like that's a bug with fetching all records then. |
locks/ember-localstorage-adapter#12 localstorage also has this issue. the non existing record remains is inserted into the store and remains in loading state. I think this issue is not a fetching-all-bug but a fetching-one-bug. |
I can confirm that requesting a record by id that doesn't exist is caught in the loading state, even after the server returns a 404. It's inconvenient that it's pushed in the store, but I can see how that might be the desired behavior. It just means that now something like
has to become
before being passed off to controllers or similar. Otherwise errors pop up when you get attributes of the errored model that are undefined and so on. It seems like having to filter through errored models is a bit unnecessary. |
I too am having an issue with this. For me, the reason it's undesirable is because I'm testing to see if I have an id, on error (it didn't exist), I'd like to create a record and push it. However, since I just searched for that id, it now exists (in error state) in the store. I still can't use it, because find() still returns an error. |
I'm also affected by this. Doing For now I'm doing:
|
I also tried following the approach form @Chenn :
But it didn't work probably to locks/ember-localstorage-adapter#12 |
So, what I ended up with is hasRecordForId to check for a record. |
@end-user thank for your observation. I've now solved with:
Looks better but still i would prefer a |
Is this supposed to be fixed on 1.0.0-beta.16.1? After a 404 I am getting phantom records which appear when doing store.all, but not via hasRecordForId |
Does |
@igorT, I mean, as detailed by the OP, if a route model's promise returns 404 (after requesting a nonexistent id), a nonexistent record is added to the store: Then, If I go to a route that requests store.all, the nonexistent record is still there. I'll try with references branch. |
@igorT Should I open an issue? |
Hoping to get |
@jsangilve do you want to write a failing test? That would be super helpful |
|
While request a nonexistent data by id, the server return 404.
for example, GET
localhost:5002/#/products/some_id_not_exists
return 404but the store still got one product with the id


some_id_not_exists
, the other fields are undefined.The text was updated successfully, but these errors were encountered: