This project is archived and is in readonly mode.
nested_attributes doesn't rollback parent when before_save/after_save callbacks fail
-
Eloy Duran
- Assigned user set to Eloy Duran
- Milestone set to 2.3.6
-
Eloy Duran
- State changed from new to incomplete
This is not intended, please do investigate further.
-
Eloy Duran
- Tag changed from 2.x, active_record, callbacks, nested_attributes_for to 2.x, active_record, callbacks
Also it doesn't really seem to have to do with nested attributes, but more with the association callbacks and possible some autosave association code.
-
Rizwan Reza
- Tag changed from 2.x, active_record, callbacks to 2.x, active_record, bugmash, callbacks
-
Eloy Duran
- Assigned user changed from Eloy Duran to José Valim
- Importance changed from to
-
Neeraj Singh
- Assigned user changed from José Valim to Neeraj Singh
I am working on #5053 child/grandchild associations reload from db after nested attributes assignment. Will take a look at this ticket too . For the time being assigning it to myself.
-
Neeraj Singh
@Ben
You have following callback.
def cause_after_save_problems raise ActiveRecord::Rollback if fail == :after_save endI am able to reproduce this problem with above callback.
However problem goes away if I change the method to this
def cause_after_save_problems raise 'boom' if fail == :after_save endlooking at code I found following snippet
rescue Exception => database_transaction_rollback if transaction_open && !outside_transaction? transaction_open = false decrement_open_transactions if open_transactions == 0 rollback_db_transaction else rollback_to_savepoint end end raise unless database_transaction_rollback.is_a?(ActiveRecord::Rollback) endThis is one place I found where my code will behave differently from yours. In mycase database_transaction_rollback will be a RuntimeError and in your case it will be ActiveRecord::Rollback. And that influences this piece of code
raise unless database_transaction_rollback.is_a?(ActiveRecord::Rollback) -
Neeraj Singh
- Assigned user cleared.
-
Santiago Pastorino
- State changed from incomplete to open
- Tag changed from 2.x, active_record, bugmash, callbacks to 2x, active_record, bugmash, callbacks
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale