Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

DatabaseCleaner improperly starts and ends transactions for ActiveRecord

Open
#24 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
databases

Research direction

Start with activerecord/lib/active_record/fixtures.rb at the referenced start and end transaction sections, then compare that flow with how ActiveRecord collects available connections. Confirm the change covers every connection in the pool: subsequent ActiveRecord calls should remain transactional, and cleanup should leave no connection with an active transaction.

Written by the indexing model from the issue text.

Description

If there is more than one connection in the connection pool DatabaseCleaner will only begin the transaction on one of the connections.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/fixtures.rb#L979

Any ActiveRecord call afterwards will use the next connection in the pool which does not have a transaction.

When DatabaseCleaner closes the transaction, it will only do so on the next active connection. Thus leaving a connection with an active transaction in the connection pool which can deadlock when doing a deletion cleanup or any table modifications.

DatabaseCleaner should start and end transactions the same way ActiveRecord does by collecting all available connections and starting transactions on all of them.

start: https://github.com/rails/rails/blob/06a9e18e646845ded0f0a46a14c1eb6b3a14e55a/activerecord/lib/active_record/fixtures.rb#L949
end: https://github.com/rails/rails/blob/06a9e18e646845ded0f0a46a14c1eb6b3a14e55a/activerecord/lib/active_record/fixtures.rb#L967

Dominant language
Ruby
Stars
76
Forks
76
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DatabaseCleaner/database_cleaner-active_record

All issues in DatabaseCleaner/database_cleaner-active_record

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.