-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
ActiveRecord attempting to autosave empty associated records after failed transactions #17570
Comments
Yeah, agree it doesn't seem correct behaviour. I believe the problem here is that the rollback of the transaction doesn't put the object in the previous state before starting the transaction so the feeling object is inside your person instance, when you save, it tries to save it again. Do you have any suggestion of what you would expect here? |
Let's say our |
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
I can confirm that this still occurs on master, but I don't think it's necessarily a bug. A transaction is supposed to rollback the state of the database upon an exception, but not the state of an object's instance data. From the docs for Transactions:
It appears that this behaviour has been around for a very long time, possibly since Rails was released. |
This issue has been automatically closed because of inactivity. If you can still reproduce this error on the Thank you for all your contributions. |
The issue happens when creating an associated record in a transaction and that transaction fails. Models for this example:
Let's create a transaction wherein a
person
gets a newfeeling
:The
feeling
is rightly rolled back whenperson.update!
fails. However, if we rescue from the exception in our transaction block and call anothersave
on the sameperson
object later, it attempts (or succeeds) to autosave a newFeeling
, but with all columns nulled out. Cannot imagine this is the correct behavior. Wanted to verify this is in fact a bug and discuss the correct behavior before I go about creating a PR.Reproduced with AR 4.0.5, 4.1.7, 4.2.0.beta4
The text was updated successfully, but these errors were encountered: