-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Can no longer access model errors after failed save #564
Comments
👋 @lindyhopchris Do you happen to have a reproduction? I added a test here and all seems ok. We only rollback changes made through the |
@snewcomer thanks for getting back to me! your test actually shows what the problem is. this line:
that shows that the value on the dummy model has been set back to the value it was before the changeset was saved. I.e. the sequence is:
However, that's the problem - setting the name back to I.e. for the Ember Data model to still have the error message for
|
I can't find any reference to it in the guides or the API docs, but basically when you set an attribute on an Ember Data model, if there is an error message for that attribute, the error message gets cleared. That's why setting the |
Oh you are right. I naively assumed the errors from the API would be set and persist regardless of the DS.Model value. So it must clear out the errors when the value is set to the previous as you have described. We are a little at odds because the underlying model is only expected to only update the underlying model upon a verified "proper" state on the changeset. I'll have to think about this! |
Yeah totally get why you're reverting the model after the save fails... does kind of make sense. Not sure what to suggest so interested to hear your thoughts once you've had a chance to think about it! |
Version
[email protected]
[email protected]
Test Case
None
Steps to reproduce
Set up a scenario where the server rejects a save with validation errors, as per this example in the readme:
Expected Behavior
model.errors
contains errorsActual Behavior
model.errors
has no errors as original value has been restored on the model, wiping the errors out.I believe this has been caused by this change:
adopted-ember-addons/validated-changeset#80
When the original value of an attribute is restored onto the model, the model clears the errors for that attribute. That means by the time the error is caught,
model.errors
contains no error messages.It is therefore no longer possible to add model errors to a changeset.
The exception that Ember Data throws does not have the parsed errors on it - it has the raw JSON:API response. So there is no way to access the parsed Ember Data errors and push them into the changeset.
The text was updated successfully, but these errors were encountered: