Skip to content

NoMethodError: undefined method `lock' for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x0000000105b1e008> #127

Open

Description

@sshaw

v2.2.2, mysql2 0.5.4, Ruby 2.7, Rails 5.

When I downgrade to 1.8 it works. Maybe a Rails version check is needed in dependency list for 2.X?

     NoMethodError:
       undefined method `lock' for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x0000000105b1e008>
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/database_cleaner-active_record-2.2.2/lib/database_cleaner/active_record/transaction.rb:20:in `block in clean'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/database_cleaner-active_record-2.2.2/lib/database_cleaner/active_record/transaction.rb:19:in `each'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/database_cleaner-active_record-2.2.2/lib/database_cleaner/active_record/transaction.rb:19:in `clean'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/strategy.rb:32:in `cleaning'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/2.7.0/forwardable.rb:235:in `cleaning'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:34:in `block (2 levels) in cleaning'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:35:in `cleaning'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/2.7.0/forwardable.rb:235:in `cleaning'
     # ./spec/rails_helper.rb:90:in `block (2 levels) in <top (required)>'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:390:in `execute_with'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:352:in `call'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:486:in `run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:259:in `run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:646:in `block in run_examples'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:642:in `map'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:642:in `run_examples'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:607:in `run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `block in run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `map'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `block in run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `map'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `map'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/configuration.rb:2068:in `with_suite_hooks'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:116:in `block in run_specs'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/reporter.rb:74:in `report'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:115:in `run_specs'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:89:in `run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:71:in `run'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:45:in `invoke'
     # /Users/sshaw/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rspec-core-3.11.0/exe/rspec:4:in `<top (required)>'
     # ./bin/rspec:17:in `load'
     # ./bin/rspec:17:in `<main>'

Config

config.use_transactional_fixtures = false  

config.before(:suite) do
  DatabaseCleaner.strategy = :transaction
  DatabaseCleaner.clean_with(:truncation)
end

config.around :each do |ex|
  DatabaseCleaner.strategy = :truncation if ex.metadata[:js]
  DatabaseCleaner.cleaning { ex.run }
  DatabaseCleaner.strategy = :transaction
end

Activity

  1. etagwerker commented on Aug 15, 2025

    @etagwerker
    Member

    Thanks for reporting this. I think this is a recent change, so have you tried using v2.2.1?

  2. sshaw commented on Aug 17, 2025

    @sshaw
    Author

    Hi, 2.2.1 works, yay, thanks. What change in 2.2.2 you think is the cause?

  3. RyanSnodgrass commented on Sep 26, 2025

    @RyanSnodgrass

    I'm getting the same issue.

    • Rails 5.0.7.2
    • mysql2 0.5.7

    Starts in database_cleaner-active_record version 2.2.0.

    Locking to 2.1.0 resolves the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions