From efb99e589600eb2939147d39126d3bea11950b99 Mon Sep 17 00:00:00 2001 From: Jordan Owens Date: Wed, 28 Aug 2024 16:17:12 -0400 Subject: [PATCH] Ensure the run_callbacks block returns a truthy value This is a further ActiveRecord 7.2 compatibility update. --- lib/activerecord-import/import.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/activerecord-import/import.rb b/lib/activerecord-import/import.rb index ca1ba6ad..bd1e2c4f 100644 --- a/lib/activerecord-import/import.rb +++ b/lib/activerecord-import/import.rb @@ -94,7 +94,7 @@ def valid_model?(model) env = ActiveSupport::Callbacks::Filters::Environment.new(model, false, nil) if runner.respond_to?(:call) # ActiveRecord < 5.1 runner.call(env) - else # ActiveRecord 5.1 + else # ActiveRecord >= 5.1 # Note that this is a gross simplification of ActiveSupport::Callbacks#run_callbacks. # It's technically possible for there to exist an "around" callback in the # :validate chain, but this would be an aberration, since Rails doesn't define @@ -107,7 +107,8 @@ def valid_model?(model) # no real-world use case for it. raise "The :validate callback chain contains an 'around' callback, which is unsupported" unless runner.final? runner.invoke_before(env) - runner.invoke_after(env) + # Ensure a truthy value is returned. ActiveRecord < 7.2 always returned an array. + runner.invoke_after(env) || [] end elsif @validate_callbacks.method(:compile).arity == 0 # ActiveRecord = 4.0 model.instance_eval @validate_callbacks.compile