zdennis/activerecord-import

Upcoming breakage with next Rails release

gravitystorm opened this issue ยท 8 comments

I was working on something completely unrelated, and came across this problem with using the latest activerecord-import version running against the current rails main branch.

runner = @validate_callbacks.compile

The signature of the Rails internal CallbackChain.compile method has recently (September 2022) changed, and now requires a type parameter (although that type can be nil, it's not optional).

-        def compile
+        def compile(type)

https://github.com/rails/rails/blob/a51e9676e611f578bdfd10fcf6891d9e2d762a23/activesupport/lib/active_support/callbacks.rb#L651-L667

It was changed in:

The error message I got in my app was "ArgumentError: wrong number of arguments (given 0, expected 1)".

I thought I'd open this issue here to give you a heads-up! I don't have any particular urgency or anything with this, so no worries if it's low priority (or ignored) until the next official Rails release is made.

Just ran into the issue. Running 7.1.0 Alpha from the main branch

Had to downgrade Rails to unblock myself. Can't wait to see the issue fixed

I confirm the issue.

I made this branch simply sending nil.

master...mathieujobin:activerecord-import:rails-7.1

Hi guys ! Any update on this ? I'm facing the same issue. Is it possible to merge the fix ?

The proposed workaround is not a complete fix that would be suitable to merge. Some more work to make sure it works with all supported Rails versions is required.

๐Ÿ‘‹ I began to implement what @jkowens was asking for:

diff --git a/lib/activerecord-import/import.rb b/lib/activerecord-import/import.rb
index 11eeab7..d761a19 100644
--- a/lib/activerecord-import/import.rb
+++ b/lib/activerecord-import/import.rb
@@ -85,7 +85,12 @@ module ActiveRecord::Import # :nodoc:
 
         model.run_callbacks(:validation) do
           if defined?(ActiveSupport::Callbacks::Filters::Environment) # ActiveRecord >= 4.1
-            runner = @validate_callbacks.compile
+            runner = if @validate_callbacks.method(:compile).arity == 0
+                       @validate_callbacks.compile
+                     else # ActiveRecord >= 7.1
+                       @validate_callbacks.compile(nil)
+                     end
+
             env = ActiveSupport::Callbacks::Filters::Environment.new(model, false, nil)
             if runner.respond_to?(:call) # ActiveRecord < 5.1
               runner.call(env)

But I realized the problem would be better fixed upstream, in Rails: rails/rails#48723

gucki commented

@jkowens As the issue won't be fixed in rails (see rails/rails#48723), can @gjtorikian fix be merged, please?

@gucki yes the fix by @gjtorikian would be good, just need a PR ๐Ÿ‘

gucki commented

@jkowens Just created it for you :-)