Skip to content

destroy_file callback not invoked #138

Open

Description

@fabn

I've just integrated attachinary in my project and everything is working. However when an Attachinary::File is destroyed remote file is not removed. My environment:

  * rails (4.2.6)
  * attachinary (1.3.1)
  * cloudinary (1.1.7)

Failing test:

it 'should remove remote file', :vcr do
  expect(Cloudinary.config.attachinary_keep_remote).to be_falsey
  expect(item.postcard).to_not be_nil
  # File should be removed
  expect(item.postcard).to receive(:destroy_file).and_call_original
  expect(Cloudinary::Uploader).to receive(:destroy).with(item.postcard.public_id).and_call_original
  item.update!(postcard: nil)
end

In any case, I think that destroy_file should be called in an after_commit callback instead of after_destroy otherwise if for any reason transaction is aborted record is no longer valid.

Activity

  1. fabn commented on Sep 24, 2016

    @fabn
    Author

    I think I've found the culprit of this issue in this line. You're calling #clear which trigger a delete_all, thus callback are not invoked.

    I'll see how to fix this and if I found a good solution I'll sketch a PR for this issue.

  2. fabn commented on Dec 20, 2016

    @fabn
    Author

    Any news about this and related PR #139??

  3. orlando commented on Dec 26, 2016

    @orlando
    Collaborator

    This looks good, but I'm worried about it will break compatibility with older versions. (I don't how people with mongoid had been handling this).

  4. fabn commented on Dec 26, 2016

    @fabn
    Author

    Compatibility with mongoid is addressed in the if statement and old versions have a bug because they don't destroy associated file on cloudinary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions