jruby / activerecord-jdbc-adapter

JRuby's ActiveRecord adapter using JDBC.
BSD 2-Clause "Simplified" License
462 stars 385 forks source link

undefined method `database_product' for nil:NilClass #1163

Closed tykonu closed 2 weeks ago

tykonu commented 2 weeks ago

Hey!

Testing out jruby on an existing MRI app (postgresql).

jruby 9.4.9.0 (3.1.4) 2024-11-04 547c6b150e OpenJDK 64-Bit Server VM 17.0.2+8 on 17.0.2+8 +jit [x86_64-darwin]

Localhost launches fine, but when opening it in the browser it seems that something is going wrong with the DB connection:

NoMethodError (undefined method `database_product' for nil:NilClass):

activerecord-jdbc-adapter-70.2 (java) lib/arjdbc/postgresql/adapter.rb:56:in redshift?' activerecord-jdbc-adapter-70.2 (java) lib/arjdbc/postgresql/adapter.rb:509:inclient_min_messages=' activerecord-jdbc-adapter-70.2 (java) lib/arjdbc/postgresql/adapter.rb:76:in configure_connection' arjdbc/jdbc/RubyJdbcConnection.java:596:inconfigure_connection' activerecord-jdbc-adapter-70.2 (java) lib/arjdbc/abstract/core.rb:25:in initialize' activerecord-jdbc-adapter-70.2 (java) lib/arjdbc/abstract/statement_cache.rb:23:ininitialize' activerecord-jdbc-adapter-70.2 (java) lib/arjdbc/postgresql/adapter.rb:769:in initialize' org/jruby/RubyClass.java:949:innew'

Extracted source around line #56:

  if ( redshift = config[:redshift] ).nil?        
        redshift = !! (@connection.database_product || '').index('Redshift')       
  end
  redshift

end

Standard database.yml, works well on MRI.

headius commented 2 weeks ago

Thanks for the report! Is your Rails app also Rails 7.0? The latest ARJDBC adapters currently released are for 7.0 and probably won't work on a Rails 7.1 or higher app.

tykonu commented 2 weeks ago

Thanks for the report! Is your Rails app also Rails 7.0? The latest ARJDBC adapters currently released are for 7.0 and probably won't work on a Rails 7.1 or higher app.

Thank you. I tried downgrading to Rails 7.0 and using the 70.0 version of the adapter and the issue was solved.

headius commented 2 weeks ago

@tykonu okay, thanks for the update. I'm going to close this, since we already have plenty of other issues tracking the rails 7.1 compatibility work.