jruby / activerecord-jdbc-adapter

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

undefined method `execute' for nil:NilClass #1139

Closed postmodern closed 10 months ago

postmodern commented 10 months ago

I started noticing an exception coming from within activerecord-jdbc-adapter-70.1-java when attempting to execute SQL statements against a sqlite3::memory: database.

Steps To Reproduce

Gemfile:

gem 'sqlite3', platform: :mri
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
gem 'activerecord'
#!/usr/bin/env ruby

begin
  require 'bundler/setup'
rescue LoadError => error
  abort error.message
end

require 'active_record'

ActiveRecord::Base.establish_connection({adapter: 'sqlite3', database: ':memory:'})
p ActiveRecord::Base.connection.execute('SELECT 1;')

CRuby

$ ruby test.rb 
[{"1"=>1}]

JRuby

$ ruby test.rb 
/home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb:13: warning: method redefined; discarding old to_int
/home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb:13: warning: method redefined; discarding old to_f
/home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/model_schema.rb:167: warning: previous definition of inheritance_column= was here
NoMethodError: undefined method `execute' for nil:NilClass
Did you mean?  exec
                         execute at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/abstract/database_statements.rb:88
                      instrument at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activesupport-7.1.3/lib/active_support/notifications/instrumenter.rb:58
                             log at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:1143
                             log at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/abstract/core.rb:72
                         execute at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/abstract/database_statements.rb:88
            configure_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/sqlite3/adapter.rb:608
            configure_connection at arjdbc/jdbc/RubyJdbcConnection.java:596
                      initialize at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/abstract/core.rb:25
                      initialize at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/sqlite3/adapter.rb:94
                      initialize at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/abstract/statement_cache.rb:23
                             new at org/jruby/RubyClass.java:931
                 jdbc_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/jdbc/connection_methods.rb:10
              sqlite3_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-70.1-java/lib/arjdbc/sqlite3/connection_methods.rb:59
                     public_send at org/jruby/RubyKernel.java:2119
                  new_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:676
         checkout_new_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:723
  try_to_checkout_new_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:702
              acquire_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:654
                        checkout at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:353
                      connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:182
             retrieve_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/connection_handler.rb:246
             retrieve_connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_handling.rb:287
                      connection at /home/postmodern/test/ruby/bundler/vendor/bundle/jruby/3.1.0/gems/activerecord-7.1.3/lib/active_record/connection_handling.rb:254
                          <main> at test.rb:12

Version Information

rdubya commented 10 months ago

Hi @postmodern, It looks like you are trying to use it with ActiveRecord 7.1, which isn't supported yet. The master branch has semi-complete support for ActiveRecord 7.1 using sqlite. We probably won't do a full release until Sqlite, MySql and Postgres are all supported though. If you get a chance, please test with that branch and open tickets for functionality that still doesn't work.

Thanks!