Duplicate Check Error When Using `import!` Method on Rails 7.2.0.beta2
k-tsuchiya-jp opened this issue · 3 comments
k-tsuchiya-jp commented
Issue Summary:
Using the import!
method to update existing data now triggers a duplicate check error.
Environment:
activerecord-import: 1.7.0
rails: 7.2.0.beta2
ruby: 3.1.6
Details:
import!
method is equipped with the on_duplicate_key_update option.- The target Model for update includes a uniqueness validation.
class Book < ApplicationRecord
validates :isbn_13, uniqueness: true
end
upsert_attributes = params.map | param | { Book.new(isbn_13: param.isbn_13, title: param.title) }
Book.import! upsert_attributes, on_duplicate_key_update: [:title]
KojiTsuchiya-Ruby commented
It seems that @compiled
is now included in the return value of klass._validate_callbacks
.
https://github.com/zdennis/activerecord-import/blob/v1.7.0/lib/activerecord-import/import.rb#L36
@compiled=
#<ActiveSupport::Callbacks::Filters::Before:0x00007fb51ac6b980
@filter=
#<ActiveRecord::Validations::UniquenessValidator:0x00007fb51ac646f8
@attributes=[:isbn_13],
@klass=
Book(id: integer, isbn_13: string, title: string, created_at: datetime, updated_at: datetime),
@options={}>,
@halted_lambda=
#<Proc:0x00007fb5255f75a8 /usr/local/bundle/gems/activesupport-7.2.0.beta2/lib/active_support/callbacks.rb:665>,
@name=:validate,
@user_callback=
#<Proc:0x00007fb51ac6b9d0 /usr/local/bundle/gems/activesupport-7.2.0.beta2/lib/active_support/callbacks.rb:384 (lambda)>,
@user_conditions=[]>,
It appears that @compiled
has been added to the return value starting from the following commit:
Commit Link
jkowens commented
Thanks for reporting this @KojiTsuchiya-Ruby!