You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm try to use the activerecord-import gem to import CSV files of "Comans" (food manufacturers). I want to insert new records and update existing records. The column used to determine whether a record is existing is the domain_name column.
Set up
I already have a Coman created in my database with year founded: 2015:
⚠️ However, after upgrading to Rails 7.2, the on_duplicate_key_update option doesn't seem to be working correctly. Instead, it produces the following records:
It seems to skip records where the domain name is in conflict.
Before upgrade: {:success=>true, :data=>{:import_errors=>[]}}
After upgrade: {:success=>true, :data=>{:import_errors=>[{:row=>1, :domain_name=>"dips.com", :errors=>["has already been taken"]}]}}
I do have the following validation on my model (which was present before the upgrade as well):
Summary
I'm try to use the activerecord-import gem to import CSV files of "Comans" (food manufacturers). I want to insert new records and update existing records. The column used to determine whether a record is existing is the
domain_name
column.Set up
I already have a Coman created in my database with
year founded: 2015
:Import to upsert
Next, I want to import this CSV. Notice that the "dips.com" record already exists from the line above.
So I make a call to import in my service:
Before the upgrading to Rails 7.2, the
on_duplicate_key_update
option was working correctly. It would result in the 3 following rows in the database:on_duplicate_key_update
option doesn't seem to be working correctly. Instead, it produces the following records:Notes / Thoughts
It seems to skip records where the domain name is in conflict.
Before upgrade:
{:success=>true, :data=>{:import_errors=>[]}}
After upgrade:
{:success=>true, :data=>{:import_errors=>[{:row=>1, :domain_name=>"dips.com", :errors=>["has already been taken"]}]}}
I do have the following validation on my model (which was present before the upgrade as well):
When I remove this validation, it works correctly. 🤷 I'm not sure what difference between Rails 7.1 and 7.2 would account for that.
Also, here is a diff of the SQL statement before and after the upgrade from Rails 7.1 to Rails 7.2
Question
Am I missing something? Is the importer expected to work with validations in this way? Should I use
validate: false
instead?The text was updated successfully, but these errors were encountered: