Data: .save() on unloaded recorder always returns a success

Created on 17 Sep 2015  ·  12Comments  ·  Source: emberjs/data

My application is using ember 1.13.8 and the RESTAdapter at the application level.

// my-route.js

model() {
  return this.store.createRecord('my-model', {});
},

afterModel(model) {
  this.store.unloadAll('my-model');
  return model
    .save()
    .then(() => {
      // Always end up here (although no AJAX requests were triggered)
    }, () => {
     // I would expect the request to fail if no AJAX calls are made
    });
}
Bug Good for New Contributors Improvement

All 12 comments

I'm pretty sure you can't save an unloaded record. Why are you unloading it before save?

@wecc the example I'm showing here is a simplified version. It just happened that part of our application was attempting to unload records from the store, while an other part was trying to save a specific model (for which it had a reference).

@wecc @olivierlesnicki I ran into this too... I don't think it's something that should be done (saving an unloaded record), but it is something that can be hard to debug... When I'm creating new records to be persisted to the server, I unload the record on a failed request. If the record was created as a controller property (don't know if it matters that it's the 'model' property), unless the property gets reset, calling save on it again will yield a misleading successful response (despite the 403 error I'm getting from the server).

I believe we error now if you attempt to do anything via an unloaded record, but we should confirm this and if not we should add more errors.

Here's a twiddle showing the an error given the code from the original post:
https://ember-twiddle.com/1334df291296cbeab788718eee3fc37f

NOTE: open the dev console to see the log output

Thanks @pete-the-pete !

👍 is there a test we should have to verify/validate this and close the issue?

@pete-the-pete I have an open PR where I paired today with @gabbyjose to add some tests specific to create record (and unload) behavior. Adding a test for this scenario there to ensure it errors would make sense.

sure thing, can you point me in the right direction? maybe a similar test I
could use as an example?

On Thu, Jun 28, 2018 at 9:01 PM Chris Thoburn notifications@github.com
wrote:

@pete-the-pete https://github.com/pete-the-pete I have an open PR where
I paired today with @Gabbyjose https://github.com/Gabbyjose to add some
tests specific to create record (and unload) behavior. Adding a test for
this scenario there to ensure it errors would make sense.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/emberjs/data/issues/3780#issuecomment-401241041, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAVHgUirQ_Q947G5PDflRQgWPuPLqMZkks5uBaaugaJpZM4F_BCd
.

@runspired i found this https://github.com/emberjs/data/pull/5509/commits/8e032b6c1e80e9bd6eb1ac50ca81619a6bf3188c, and will use that as a guide unless you suggest something else.

@pete-the-pete that’s the one I meant!

Resolved in #5512

Was this page helpful?
0 / 5 - 0 ratings