rubysherpas / paranoia

acts_as_paranoid for Rails 5, 6 and 7
Other
2.87k stars 524 forks source link

Fix create callback called on destroy #513

Closed bkDJ closed 2 years ago

bkDJ commented 2 years ago

We were running into a weird bug in one of our projects while migrating from Rails 5.2 to Rails 6.0. It seems to be due to Rails using #with_transaction_returning_status when persisting models which takes care of setting the recently-added ivar @_new_record_before_last_commit. Paranoia overrides ActiveRecord's #destroy with #paranoia_destroy which unfortunately only uses #transaction, so when checking for which callbacks should be run, it was seeing a stale value of @_new_record_before_last_commit, therefore causing after_create_commit hooks to be called again.

mathieujobin commented 2 years ago

can you please rebase your branch with core so the tests run? Thanks

rchasman commented 2 years ago

Would really appreciate getting this fix into the wild :)

arlando commented 2 years ago

@mathieujobin is the requirement just rebasing the branch to core and this will be GTG? thnx

mathieujobin commented 2 years ago

I will have another review after I see all tests passing But it looked fine from what I remember.

mathieujobin commented 2 years ago

I have rebased this branch into a new branch. all tests passed. including with the test in #522

I will release later

https://github.com/rubysherpas/paranoia/actions/runs/2026193146