pennylane-hq / activerecord-adapter-redshift

Other
6 stars 27 forks source link

uninitialized constant ActiveRecord::ConnectionAdapters::Redshift::DatabaseStatements::PG (NameError) #31

Closed negipo closed 6 months ago

negipo commented 6 months ago

In v1.0.3, activerecord7-redshift-adapter-pennylane calls pg gem internal constants such as PG::PQTRANS_IDLE without requiring pg.

irb(main):001> Redshift::Client.select 'select * from records limit 1'
/app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_7_1/database_statements.rb:141:in `<module:DatabaseStatements>': uninitialized constant ActiveRecord::ConnectionAdapters::Redshift::DatabaseStatements::PG (NameError)

        IDLE_TRANSACTION_STATUSES = [PG::PQTRANS_IDLE, PG::PQTRANS_INTRANS, PG::PQTRANS_INERROR]
                                     ^^
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_7_1/database_statements.rb:6:in `<module:Redshift>'
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_7_1/database_statements.rb:5:in `<module:ConnectionAdapters>'
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_7_1/database_statements.rb:4:in `<module:ActiveRecord>'
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_7_1/database_statements.rb:3:in `<main>'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /app/vendor/bundle/ruby/3.3.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /app/vendor/bundle/ruby/3.3.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_7_1_adapter.rb:15:in `<main>'
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_adapter.rb:4:in `require_relative'
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord7-redshift-adapter-pennylane-1.0.3/lib/active_record/connection_adapters/redshift_adapter.rb:4:in `<main>'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /usr/local/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /app/vendor/bundle/ruby/3.3.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /app/vendor/bundle/ruby/3.3.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
    from /app/vendor/bundle/ruby/3.3.0/gems/activerecord-7.1.3.2/lib/active_record/connection_adapters/abstract/connection_handler.rb:333:in `resolve_pool_config'
    ... 28 levels...

We wrote some require 'pg' before model using redshift to avoid this issue.

quentindemetz commented 6 months ago

Hi @negipo, I added a require 'pg' at the very top of the gem in https://github.com/pennylane-hq/activerecord-adapter-redshift/commit/6bea9c3fd6cf2c03b948a76f2fe87d4ba4ed00e3 - does that fix your issue?

negipo commented 6 months ago

Hi, @quentindemetz

I have checked the issue via

# In Gemfile:
gem 'activerecord7-redshift-adapter-pennylane', github: 'pennylane-hq/activerecord-adapter-redshift'

# In Gemfile.lock:
GIT
  remote: https://github.com/pennylane-hq/activerecord-adapter-redshift.git
  revision: 6bea9c3fd6cf2c03b948a76f2fe87d4ba4ed00e3
  specs:
    activerecord7-redshift-adapter-pennylane (1.0.4)
      activerecord (~> 7.0)
      pg (~> 1.0)

and the check was succeed! Thank you for your quick response :D