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

shouldBackgroundReloadRecord is background reloading unsaved records #3678

Closed
mcrummey opened this issue Aug 20, 2015 · 10 comments
Closed

shouldBackgroundReloadRecord is background reloading unsaved records #3678

mcrummey opened this issue Aug 20, 2015 · 10 comments
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@mcrummey
Copy link

When a record is created and we transition to that route, Ember data does a background reload that results in a 404 from the database and the exception.

export default Ember.Controller.extend({
    actions: {
        newForm: function () {
            var form = this.store.createRecord("form-design", {
                name: "NewForm",
                description: "Created but not saved",
                rev: "",
                formObjects: []
            });
            this.transitionToRoute("form-design", form.get("id"));
        }
    }
});

In order to inhibit the background reload we put a "isNew" check into our adapter.

shouldBackgroundReloadRecord: function (store, snapshot) {
    // We don"t ever want to background reload a new record do we?
    return !snapshot.record.get("isNew");
}

I can't think of a use case where ember data would want to do a background reload on records that are not saved.

Ember data should inhibit background reloading by default for unsaved records.

@decasia
Copy link

decasia commented Sep 30, 2015

I'm seeing this issue with non-background reloading (I have shouldReloadAll set to true, and after a bit of random navigation to and from a record, Ember starts hitting my back end with requests for a record with a null ID).

This seems like a clear bug — if someone from ember data can give me any guidance about where to dig into this, I can try to learn enough about the architecture to submit a failing test PR or maybe a fix. @bmac maybe?

@decasia
Copy link

decasia commented Sep 30, 2015

As an update, the error I see reads like this:

Attempted to handle event `notFound` on <students_ui@model:dos-document::ember2109:null> while in state root.loaded.created.uncommitted

@bmac
Copy link
Member

bmac commented Sep 30, 2015

Hi @decasia. Feel free to ping me on the ember community slack. I think a good place to start debugging this would be adding a breakpoint to the store's scheduleFetch to try to figure out where/why Ember Data is initiating the request for a record in the isNew state.

@pangratz
Copy link
Member

pangratz commented May 23, 2016

@mcrummey looking at the code you posted, it seems that you are transitioning to the form-design route via this.transitionToRoute("form-design", form.get("id"));. As far as I can see the form doesn't have an ID yet, since it is a new record? I don't know the implementation of the model() hook of the form-design route, but is it possible that it triggers the load of the new record?


Did you have time to dig into this more with the hint @bmac suggested?

@wecc
Copy link
Contributor

wecc commented Oct 22, 2016

ping @mcrummey @decasia

@mcrummey
Copy link
Author

@pangratz @wecc @decasia The form is a new record and the the id is populated with a UUID client side.

So form.get("id") returns something like "ef42540f-7dce-4b40-9b4f-4feb7299f782".

@wecc
Copy link
Contributor

wecc commented Oct 22, 2016

@mcrummey If you already have access to the new record you should be able to pass the record to the transition to bypass the model() hook, like this:

this.transitionToRoute("form-design", form);

That said, having client side IDs with new records should probably not default to true in shouldBackgroundReloadRecord. I'd be open to a PR changing this behavior... @bmac @pangratz what do you think?

@mcrummey
Copy link
Author

@wecc Passing the object works and it does not trigger shouldBackgroundReloadRecord().

@pangratz pangratz added the Bug label Oct 22, 2016
@pangratz
Copy link
Member

This is a bug. I am working on a fix.

@runspired
Copy link
Contributor

This was resolved by the above PR, but we forgot to close it. Closing now :)

@runspired runspired added 🏷️ bug This PR primarily fixes a reported issue and removed Bug labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
Development

No branches or pull requests

6 participants