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

Rails 6 and 7 break kt-paperclip due to lack of :on support in callbacks #126

Open
wedgemartin opened this issue Nov 6, 2023 · 4 comments
Assignees

Comments

@wedgemartin
Copy link

wedgemartin commented Nov 6, 2023

Describe the bug
In Rails 6 and above, kt-paperlcip fails on line 98 in lib/paperclip/has_attached_file.rb where an :on condition is used for after_commit / destroy


 93     def add_active_record_callbacks
 94       name = @name
 95       @klass.send(:after_save) { send(name).send(:save) }
 96       @klass.send(:before_destroy) { send(name).send(:queue_all_for_delete) }
 97       if @klass.respond_to?(:after_commit)
 98         @klass.send(:after_commit, on: :destroy) do
 99           send(name).send(:flush_deletes)
100         end
101       else
102         @klass.send(:after_destroy) { send(name).send(:flush_deletes) }
103       end
104     end

To Reproduce
Steps to reproduce the behavior:

  1. Implement has_attached_file with any settings
  2. Attempt an rspec run, rails console, or start a puma server etc.
  3. Error will get thrown to the console
ArgumentError:
  Unknown key: :on. Valid keys are: :if, :unless, :prepend

Expected behavior
Should function normally.

Desktop (please complete the following information):

  • Amazon Linux2 and macos
  • All versions

Looks like someone else has hit this:
https://stackoverflow.com/questions/76966547/rails-7-argumenterror-unknown-key-on-valid-keys-are-if-unless-prepend

@tomsoft1
Copy link

tomsoft1 commented Nov 9, 2023

Same problem with Rails 6 here....

@wedgemartin
Copy link
Author

For now, you can just fork kt-paperclip, and comment out the :after_commit part. This is what uses the :on operator and throws the error. Leave the :after_destroy, just remove it from the if/else

@ssinghi ssinghi self-assigned this Dec 16, 2023
@ssinghi
Copy link

ssinghi commented Jan 15, 2024

@tomsoft1 and @wedgemartin can you please provide more details. The :onkey seems to be supported by after_commit in Rails 6, and ActiveRecord: https://api.rubyonrails.org/v6.0.2.2/

Are you using some other ORM? cn you please share some sample code repo/example.

@wedgemartin
Copy link
Author

@tomsoft1 and @wedgemartin can you please provide more details. The :onkey seems to be supported by after_commit in Rails 6, and ActiveRecord: https://api.rubyonrails.org/v6.0.2.2/

Are you using some other ORM? cn you please share some sample code repo/example.

Mongoid

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

3 participants