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

Adding an error to an already invalid record throws unhandled becameInvalid event #3707

Closed
offirgolan opened this issue Aug 26, 2015 · 7 comments
Assignees

Comments

@offirgolan
Copy link

Ember Data > 1.13.6
JSBin: http://emberjs.jsbin.com/tapeva/edit?html,js,output

  1. Change ember-data to 1.13.7 or above
  2. Type in text field
  3. Focus out
  4. Type in text field again
  5. Focus out
  6. Error will be shown in console

Error: Attempted to handle event 'becameInvalid' on <App.Book:ember418:null> while in state root.loaded.created.invalid.

Original StackOverflow Post

@tomdrn
Copy link

tomdrn commented Aug 27, 2015

Same problem for me. It seems that removing the model's error do not send the event 'becameValid' even if the model has no error.

@bmac
Copy link
Member

bmac commented Aug 27, 2015

@tchak I'm not sure what the expected behavior is here. Do you mind taking a look at this issue?

@offirgolan
Copy link
Author

@bmac i believe this issue was introduced through PR #3555 but don't quote me on that.

@tchak
Copy link
Member

tchak commented Aug 28, 2015

will investigate tonight or tomorrow

@tchak tchak self-assigned this Aug 28, 2015
stefanpenner added a commit to stefanpenner/data that referenced this issue Sep 3, 2015
@stefanpenner
Copy link
Member

I tried to replicate in test form, but was unable to. @offirgolan maybe you can use my PR as a stepping stone?

@offirgolan
Copy link
Author

Okay so after a long time of debugging I figured out what's going on. @stefanpenner couldn't replicate the issue since it was actually fixed but I dont know when or how. Here is my findings:

This is how the flow should be:

  1. start in root.loaded.created.uncommitted state
  2. Add an error which will put the record in root.loaded.created.invalid state
  3. Change value of model.firstName which will trigger didSetProperty from the invalid state. This will call errors.remove which will put you back in root.loaded.created.uncommitted state

This is what was actually happening

  1. start in root.loaded.created.uncommitted state
  2. Add an error which will put the record in root.loaded.created.invalid state
  3. Change value of model.firstName which will trigger didSetProperty from the invalid state. This will call errors.remove

In errors.remove you are replacing the content of the ArrayProxy (set(this, 'content', content);). What is weird about this, is that even though content.length is 0, this.get('length') is 1. Because of this becameValid is never triggered and the record never gets put back into root.loaded.created.uncommitted. It continues to to be in the root.loaded.created.invalid state. When you go to try and add another error we again trigger a becameInvalid event which doesnt exist under the invalid state.

I was able to replicate the issue up until 2.1.0-beta.1 but once I switched over to 2.2.0-canary, this issue was resolved.

@tchak
Copy link
Member

tchak commented Oct 15, 2015

If I remember correctly it was a bug with ArrayProxies temporary introduced in some minor version of Ember. I am pretty confident to close it. Feel free to reopen if needed.

@tchak tchak closed this as completed Oct 15, 2015
bmac pushed a commit to bmac/data that referenced this issue Dec 4, 2015
bmac added a commit that referenced this issue Dec 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants