Skip to content

Octopus error at startup with Rails 6: alias_method': undefined method any?' for class `ActiveRecord::Associations::CollectionAssociation' (NameError) #540

@GuiTeK

Description

@GuiTeK

Hi,

I'm trying to get Octopus working with my Rails 6 application. What I want to achieve is to use an AWS RDS read-replica for the read-only queries of my Rails application.

I'm using Octopus v. 0.10.2. Gemfile:

gem 'ar-octopus', '~> 0.10.2'

Here is what my MY-PROJECT/config/shards.yml looks like:

---
octopus:
  environments:
  - production
  replicated: true
  fully_replicated: true
  production:
    rds_read_replica:
      adapter: postgresql
      host: XXX.eu-west-1.rds.amazonaws.com
      port: '5432'
      database: XXX
      username: XXX
      password: XXX
      encoding: utf8

However, when I run bundle exec rails server, I have the huge cryptic error below. The application works fine without Octopus. Do you have an idea of what can cause this problem?

Error:

/srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/shard_tracking.rb:23:in `alias_method': undefined method `any?' for class `ActiveRecord::Associations::CollectionAssociation' (NameError)
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/shard_tracking.rb:23:in `create_sharded_method'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/shard_tracking.rb:12:in `block in sharded_methods'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/shard_tracking.rb:12:in `each'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/shard_tracking.rb:12:in `sharded_methods'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/collection_association.rb:9:in `included'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/collection_association.rb:17:in `include'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus/collection_association.rb:17:in `<main>'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/octopus.rb:189:in `<main>'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/ar-octopus-0.10.2/lib/ar-octopus.rb:1:in `<main>'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
        from /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/runtime.rb:76:in `each'
        from /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/runtime.rb:76:in `block in require'
        from /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/runtime.rb:65:in `each'
        from /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/runtime.rb:65:in `require'
        from /usr/local/bundle/gems/bundler-2.0.2/lib/bundler.rb:114:in `require'
        from /srv/MY-PROJECT/config/application.rb:20:in `<main>'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:141:in `block in perform'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `tap'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `perform'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command/base.rb:65:in `perform'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command.rb:46:in `invoke'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
        from /srv/MY-PROJECT/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
        from bin/rails:9:in `<main>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions