Skip to content
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

after_commit on: :destroy is never called #51

Open
anark opened this issue Aug 14, 2015 · 3 comments
Open

after_commit on: :destroy is never called #51

anark opened this issue Aug 14, 2015 · 3 comments

Comments

@anark
Copy link

anark commented Aug 14, 2015

If I have an after commit hook on a destroy action on a model it will never be called when the model uses permanent records.

class TestModel < ActiveRecord::Base
  after_commit :commit_delete, on: :destroy
  def commit_delete
    puts "Commiting Delete"
  end
end

test = TestModel.create
test.destroy
=> true

This is problematic when deleting files with attachments in paperclip as paperclip relies on after_commit on delete to remove files from the filesystem.

@toddp
Copy link

toddp commented Oct 31, 2015

I've also noticed that my after_save callback does get called after I delete a record.

I think the after_commit, after_save, etc callbacks detect when some record has changed, and then fires or not accordingly. So when permanent_records updates a record's deleted_at field, that looks like a modified record and thus after_save fires.

I think those AR callback methods will need to be monkey-patched to get the right behavior in these cases.

@JackDanger
Copy link
Owner

@anark @toddp Apologies for the super long delay in addressing this. Would either of you like to create a failing test case and we can fix this?

@fabn
Copy link

fabn commented Oct 16, 2020

5 years later this is still an issue

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

No branches or pull requests

4 participants