Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 'uninitialized constant ... ::PG' when trying to use activerecord-jdbc-adapter with Postgres #1105

Open
rubycoder opened this issue Feb 27, 2022 · 0 comments

Comments

@rubycoder
Copy link

Trying to use ActiveRecord with Postgres on JRuby 9.3.3.0, java 16.0.2, activerecord 6.1.4.6, activerecord-jdbc-adapter 61.1 java on Mac Catalina 10.15.7, with the Postgres server running. Tried to follow the instructions at github.com/jruby/activerecord-jdbc-adapter . I see the error:

NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PG

This is my code:

require 'active_record'
require 'activerecord-jdbc-adapter' if defined? JRUBY_VERSION

ActiveRecord::Base.establish_connection(
  adapter:  "postgresql",
  host:     "localhost",
  database: "test",
  username: "postgres",
  password: "password")

The stack trace contains the entry

<class:PostgreSQLAdapter> at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:937

Line 937 is

class MoneyDecoder < PG::SimpleDecoder # :nodoc:

So ActiveRecord is subclassing a class in PG, but PG won't build on JRuby. Tried doing 'gem install activerecord-postgresql-adapter' but the install fails because that gem also depends on the 'pg' gem.

Tried the line "require 'activerecord-jdbcpostgresql-adapter' if defined? JRUBY_VERSION" either instead of or in addition to the require 'activerecord-jdbc-adapter' but I still get the same 'uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PG', and essentially the same stack trace.

I posted this issue to stackoverflow on 2/13/22: https://stackoverflow.com/questions/71097449/jruby-how-to-use-the-activerecord-postgresql-adapter-without-pg-which-is-wri. This issue on github is slightly more up-to-date than the one on stackoverflow.

I imagine I'm making some mistake, but I haven't been able to find it. I'm using the latest versions of all the gems. Thanks!!!

/bin/zsh -c "bash -c '/Users/test/.rvm/bin/rvm jruby-9.3.3.0 do /Users/test/.rvm/rubies/jruby-9.3.3.0/bin/jruby /Users/test/RubymineProjects/glimmer/TaskTimer2/lib/test_github.rb'"
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PG
        load_missing_constant at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activesupport-6.1.4.6/lib/active_support/dependencies.rb:603
                const_missing at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activesupport-6.1.4.6/lib/active_support/dependencies.rb:213
    <class:PostgreSQLAdapter> at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:937
  <module:ConnectionAdapters> at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:73
        <module:ActiveRecord> at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:45
                       <main> at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:22
                      require at org/jruby/RubyKernel.java:1017
                      require at /Users/test/.rvm/rubies/jruby-9.3.3.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
                      require at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activesupport-6.1.4.6/lib/active_support/dependencies.rb:332
              load_dependency at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activesupport-6.1.4.6/lib/active_support/dependencies.rb:299
                      require at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activesupport-6.1.4.6/lib/active_support/dependencies.rb:332
          resolve_pool_config at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1205
         establish_connection at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1046
         establish_connection at /Users/test/.rvm/gems/jruby-9.3.3.0/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:52
                       <main> at /Users/test/RubymineProjects/glimmer/TaskTimer2/lib/test_github.rb:4

Process finished with exit code 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant