Data: Uncaught Error: Attempted to handle event `didSetProperty`

Created on 5 Mar 2016  路  5Comments  路  Source: emberjs/data

First off, sorry about the title. I'm at a loss with summing up this bug up into a title. Hopefully we can do that together and rename the issue.

I help maintain emberx-select and had this bug reported on x-select. If you set the value of x-select to a property on the model (i.e. value=model.name), rollback the model, and try to select another item in the <select> it will throw this error:

Uncaught Error: Attempted to handle event `didSetProperty` on <xselect-example@model:wombat::ember441:null> while in state root.deleted.saved. Called with {name: name, oldValue: undefined, originalValue: undefined, value: Wombatus}.

Here is an app that replicates this behavior.

Here is the example repo

Steps to reproduce:

  1. Select a new option from the select
  2. Click the "rollback" button
  3. Check console for error

    Expected Behavior:

The value of x-select is set to the option selected _after_ the rollback.

Actual Behavior:

It throws an error and never resets the value of the x-select component.

Ember CLI / Ember / Ember Data Versions:

Ember CLI: 2.2.0-beta.6
Ember: at least 1.13-2.3.0
Ember Data: at least 1.13-2.3.0

You can see the ember try scenerio here. You can also see the test output here.

Most helpful comment

This should still be addressed. Either rollbackAttributes should print an error, or it should do the right thing. Otherwise, it shouldn't be available on a new model.

All 5 comments

So I suspected this may have something to do with new records only. I confirmed this by changing the code in the route to:

export default Ember.Route.extend({
  model() {
    var payload = {
      data: {
        id: 1,
        type: 'wombat',
        attributes: {
          name: 'lol'
        }
      }
    };

    this.store.pushPayload('wombat', payload);
    return this.store.peekRecord('wombat', 1);
  },
});

And the error doesn't occur. Seems to be funky with the internal state machine on new records.

Seems to be funky with the internal state machine on new records.

When a new record is rolled back via rollbackAttributes(), it is in the root.deleted.saved state. In this state the record is more or less useless and you can't set properties anymore (i.e. there is no didSetProperty handler in this state).

So state-machine wise, rolling back a new record indicates ember-data that this record is not needed anymore.


So the "solution" in this case is either not to rollback when the record is still needed, or set a newly created record if you need to have a "fresh" state (and do the rollback on the "old" record, so it is properly cleared up).

As pointed out in the linked issue thefrontside/emberx-select#94 the problem is resolved by not setting the value when the component is teared down.

The thrown error about the unhandled didSetProperty event is not really a bug, since that's the way how the state machine currently is intended to work: a locally created model, which is rolled back should not be used further.

@Robdel12 I am going to close this issue. Thanks for the detailed report though! It was immediately clear what the issue was you were having! :rocket: :+1:

My project also had this problem. So it is mean if I have I new record want to rollback, not use rollbackAttributes(). Just like this this.set('model', this.store.createRecord('product')); ? Thanks.

This should still be addressed. Either rollbackAttributes should print an error, or it should do the right thing. Otherwise, it shouldn't be available on a new model.

Was this page helpful?
0 / 5 - 0 ratings