Skip to content

Commit

Permalink
Ensure the run_callbacks block returns a truthy value
Browse files Browse the repository at this point in the history
This is a further ActiveRecord 7.2 compatibility update.
  • Loading branch information
jkowens committed Aug 28, 2024
1 parent 9d71064 commit efb99e5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/activerecord-import/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit efb99e5

Please sign in to comment.