Skip to content

Conversation

@arbesulo
Copy link

@arbesulo arbesulo commented Apr 22, 2020

fixes #5430

When submitting a form with invalid attributes, some associations are autosaved via assign_attributes before calling save_resource. As a consequence, when updating a resource, the user sees a validation error and is not aware that the changes to the associations got persisted.

This PR runs the code inside the update_resource method in an ActiveRecord::Transaction so that everything is rolled back when the model is not valid.

@arbesulo
Copy link
Author

I need some help with the regression tests... Can anybody point me in the right direction?

@legendado
Copy link

Tested on real project. Works fine 👍

@arbesulo
Copy link
Author

arbesulo commented Apr 8, 2022

closing due to lack of help... I hope this works already on the stable branches

@deivid-rodriguez
Copy link
Member

Thanks @arbesulo, sorry nobody was able to help out. I created an updated copy of this PR, this seems useful work, so by keeping an open PR maybe some will eventually get to ir.

@deivid-rodriguez
Copy link
Member

By the way, this seems like a Rails issue? Is there any open report about this?

@arbesulo
Copy link
Author

arbesulo commented Apr 8, 2022

@deivid-rodriguez honestly I haven't checked if there is any open issue in rails related to this.

Also I'm no longer in the project where this issue arised, so I don't know if the current version still has it or not.

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

Successfully merging this pull request may close these issues.

Associations are persisted before validation of main record

3 participants