Skip to content

Commit

Permalink
Merge pull request #72 from lml/rails-7-1-transaction-isolation
Browse files Browse the repository at this point in the history
Don't even try to set transaction isolation in Rails 7.1 if a transac…
  • Loading branch information
chrisbendel authored Mar 11, 2024
2 parents b510baf + d2f4e77 commit fd1c4c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/lev/routine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,15 @@ def runner=(runner)
def in_transaction(options={})
if transaction_run_by?(self)
isolation_symbol = self.class.transaction_isolation.symbol
if ActiveRecord::VERSION::MAJOR >= 4
if (ActiveRecord::VERSION::MAJOR >= 8 ||
(ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR >= 1)) &&
ActiveRecord::Base.connection.transaction_open?
# Don't even try to set transaction isolation if the transaction is already open
ActiveRecord::Base.transaction do
yield
raise ActiveRecord::Rollback if errors?
end
elsif ActiveRecord::VERSION::MAJOR >= 4
begin
ActiveRecord::Base.transaction(isolation: isolation_symbol) do
yield
Expand Down

0 comments on commit fd1c4c2

Please sign in to comment.