zdennis / activerecord-import

A library for bulk insertion of data into your database using ActiveRecord.
http://www.continuousthinking.com
MIT License
4.03k stars 619 forks source link

alias_attribute causing "specified more than once" error upon import. #810

Open skunkworker opened 1 year ago

skunkworker commented 1 year ago

Related to https://github.com/zdennis/activerecord-import/pull/799 and https://github.com/zdennis/activerecord-import/issues/728

In my model I am aliasing an attribute, when I try to import a record from an existing record, the INSERT INTO sql string has the aliased column name twice instead of once.

Rails 6.1.7.6 activerecord-import v1.5.0

The ActiveRecord Schema cache is also being used.

Eg:

class Foobar < ApplicationRecord
  alias_attribute :myname, :name
end

Foobar.import(other_record)
=> 
ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: column "name" specified more than once
jkowens commented 1 year ago

@leonidkroka any ideas how to resolve this issue?

jkowens commented 1 year ago

Just to add more context, this seems specific to JRuby and PostgreSQL. I've added JRuby 9.4/AR 7 and 9.3/AR6 6.1 to the CI tests and they are passing 🤔

jkowens commented 1 year ago

@skunkworker what version of activerecord-jdbcpostgresql-adapter gem do you have installed?

skunkworker commented 1 year ago

@jkowens activerecord-jdbcpostgresql-adapter (61.2-java) We haven't moved to 9.4 yet because it's not stable enough for production use.

jkowens commented 1 year ago

@skunkworker I have jruby back in the CI, could you possibly create a PR with a failing test to demonstrate the issue?

skunkworker commented 1 year ago

@jkowens https://github.com/zdennis/activerecord-import/pull/817 I was able to reproduce this with jruby and MRI, the issue appears to occur when you have an alias_attribute :new_col, :old_col where both columns are currently being backed in the database.