rollbackAttributes() not working after more than one 422 error

Emberjs: 1.13.7
Ember Data: 1.13.8

I have an API server that I have just updated to serve 422 error responses when server side validation fails. My ember app is configured to use ActiveModelAdapter.

These 422 responses have a body which works to populate model.errors:

{"errors":{"name":["Name can't be blank","Name is too short (minimum is 10 characters)"],"description":["Description can't be blank"]}}

When I save a model from ember data and receive a 422 response, the model.errors object contains the expected error messages from the response. If I rollbackAttributes on the model after the single 422 failure, the attributes are rolled back correctly.

If I save a model two or more times and receive 422 errors on each attempt, model.errors still looks correct. If I rollbackAttributes on the model at this point, the original attributes are NOT restored. I can see that the original values are still available in the data attribute of the model, so I don’t know why they can’t be rolled back.

Is this something unique to my app, or is it a bug in ember-data?

I would like to write a test to reproduce this problem so I can make a bug report. How can I simulate the 422 error response behavior in the ActiveModelAdapter? I can’t find any tests in the ember-data codebase that simulate a 422 response.

I tried this in a model test, but it doesn’t reproduce the bug:

test('it rolls attributes back after multiple failed saves', function(assert) {
  var model = this.subject();
  Ember.run(function() {
    model.set('name', 'Jacks Teller');
    model.save();
  });

  model.store.adapter.updateRecord = function() {
    return Ember.RSVP.reject();
  };

  Ember.run(function() {
    model.set('name', 'Clay Morrow');
    model.save().then(null, function() {
      model.save().then(null, function() {
        model.rollbackAttributes();
        assert.equal(model.get('name'), "Jacks Teller");
      });
    });
  });
});

This test just fails during the first update with an “Error: Adapter operation failed” message.

I filed a bug report on this. I used output from the browser console to illustrate the bug since I can’t figure out how to test it. If anyone has ideas on how to test this, please let me know!

The forum won’t let me post links… so:

https:// github.com/emberjs/data/issues/3677