{"action":"created","issue":{"url":"https://api.github.com/repos/assembler/attachinary/issues/138","repository_url":"https://api.github.com/repos/assembler/attachinary","labels_url":"https://api.github.com/repos/assembler/attachinary/issues/138/labels{/name}","comments_url":"https://api.github.com/repos/assembler/attachinary/issues/138/comments","events_url":"https://api.github.com/repos/assembler/attachinary/issues/138/events","html_url":"https://github.com/assembler/attachinary/issues/138","id":179022990,"number":138,"title":"destroy_file callback not invoked","user":{"login":"fabn","id":324213,"avatar_url":"https://avatars.githubusercontent.com/u/324213?v=3","gravatar_id":"","url":"https://api.github.com/users/fabn","html_url":"https://github.com/fabn","followers_url":"https://api.github.com/users/fabn/followers","following_url":"https://api.github.com/users/fabn/following{/other_user}","gists_url":"https://api.github.com/users/fabn/gists{/gist_id}","starred_url":"https://api.github.com/users/fabn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabn/subscriptions","organizations_url":"https://api.github.com/users/fabn/orgs","repos_url":"https://api.github.com/users/fabn/repos","events_url":"https://api.github.com/users/fabn/events{/privacy}","received_events_url":"https://api.github.com/users/fabn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-24T10:15:20Z","updated_at":"2016-09-24T10:36:48Z","closed_at":null,"body":"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:\r\n\r\n```\r\n  * rails (4.2.6)\r\n  * attachinary (1.3.1)\r\n  * cloudinary (1.1.7)\r\n```\r\n\r\nFailing test:\r\n\r\n```ruby\r\nit 'should remove remote file', :vcr do\r\n  expect(Cloudinary.config.attachinary_keep_remote).to be_falsey\r\n  expect(item.postcard).to_not be_nil\r\n  # File should be removed\r\n  expect(item.postcard).to receive(:destroy_file).and_call_original\r\n  expect(Cloudinary::Uploader).to receive(:destroy).with(item.postcard.public_id).and_call_original\r\n  item.update!(postcard: nil)\r\nend\r\n```\r\n\r\nIn 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."},"comment":{"url":"https://api.github.com/repos/assembler/attachinary/issues/comments/249358073","html_url":"https://github.com/assembler/attachinary/issues/138#issuecomment-249358073","issue_url":"https://api.github.com/repos/assembler/attachinary/issues/138","id":249358073,"user":{"login":"fabn","id":324213,"avatar_url":"https://avatars.githubusercontent.com/u/324213?v=3","gravatar_id":"","url":"https://api.github.com/users/fabn","html_url":"https://github.com/fabn","followers_url":"https://api.github.com/users/fabn/followers","following_url":"https://api.github.com/users/fabn/following{/other_user}","gists_url":"https://api.github.com/users/fabn/gists{/gist_id}","starred_url":"https://api.github.com/users/fabn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabn/subscriptions","organizations_url":"https://api.github.com/users/fabn/orgs","repos_url":"https://api.github.com/users/fabn/repos","events_url":"https://api.github.com/users/fabn/events{/privacy}","received_events_url":"https://api.github.com/users/fabn/received_events","type":"User","site_admin":false},"created_at":"2016-09-24T10:36:48Z","updated_at":"2016-09-24T10:36:48Z","body":"I think I've found the culprit of this issue in [this line](https://github.com/assembler/attachinary/blob/master/lib/attachinary/orm/active_record/extension.rb#L39). You're calling [#clear](http://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-clear) which trigger a delete_all, thus callback are not invoked.\r\n\r\nI'll see how to fix this and if I found a good solution I'll sketch a PR for this issue."}}
{"actor":{"display_login":"fabn"}}