pennylane-hq / activerecord-adapter-redshift

Other
6 stars 27 forks source link

NotImplementedError with internal_exec_query #11

Closed negipo closed 8 months ago

negipo commented 10 months ago

Our project using activerecord7-redshift-adapter and ActiveRecord 7.1.1

In Gemfile.lock:

GIT
  remote: https://github.com/pennylane-hq/activerecord7-redshift-adapter.git
  revision: 1a88a550dc425e9466957856b52031c89dfe0f21
  specs:
    activerecord7-redshift-adapter (1.0.0)
      activerecord (~> 7.0)
      pg (~> 1.0)
...

    activerecord (7.1.1)

We cannot query anything because of NotImplementedError with internal_exec_query:

bin/rails console
Loading development environment (Rails 7.1.1)
[1] pry(main)> ActivityLog.count # <= Model using activerecord7-redshift-adapter
NotImplementedError: NotImplementedError
from /Users/.../.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:509:in `internal_exec_query'
[2] pry(main)>

Rails renames exec_query into internal_exec_query in recent release (https://github.com/rails/rails/pull/48069). activerecord7-redshift-adapter seems implementing exec_query, it should be renamed.


In our case, some monkey patch works.

In config/initializers/monkey_patches/activerecord7_redshift_adapter.rb:

require 'active_record/connection_adapters/redshift_adapter'

module ActiveRecord::ConnectionAdapters::Redshift::DatabaseStatements
  alias internal_exec_query exec_query
end
[1] pry(main)> ActivityLog.count
  ActivityLog Count (...)  SELECT COUNT(*) FROM ...
=> ...
[2] pry(main)>
cedvw commented 10 months ago

I have the same issue after upgrading to Rails 7.1, and negipo's solution is working for me as well.

zaru commented 8 months ago

Seems to have been reverted in Rails 7.1.2. https://github.com/rails/rails/pull/48188

owst commented 8 months ago

@zaru I think the revert was itself reverted - https://github.com/rails/rails/pull/48229

I'm seeing this error when using Rails 7.1.2

quentindemetz commented 8 months ago

Implemented via https://github.com/pennylane-hq/activerecord7-redshift-adapter/commit/0cc13d21e3561af2e6cf25f967f08369a6f0a3fa - thank you for your contribution!