Skip to content

Commit b26d642

Browse files
authored
Exist queries are retryable (#1294)
1 parent f3c4d33 commit b26d642

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _construct_relation_for_exists(conditions)
3333
end
3434
# End of monkey-patch
3535
else
36-
relation = except(:select, :distinct, :order)._select!(::ActiveRecord::FinderMethods::ONE_AS_ONE).limit!(1)
36+
relation = except(:select, :distinct, :order)._select!(Arel.sql(::ActiveRecord::FinderMethods::ONE_AS_ONE, retryable: true)).limit!(1)
3737
end
3838

3939
case conditions

test/cases/coerced_tests.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,3 +2803,14 @@ def test_with_recursive_coerced
28032803
end
28042804
end
28052805

2806+
module ActiveRecord
2807+
class AdapterConnectionTest < ActiveRecord::TestCase
2808+
# Original method defined for core adapters.
2809+
undef_method :raw_transaction_open?
2810+
def raw_transaction_open?(connection)
2811+
connection.instance_variable_get(:@raw_connection).query("SELECT @@trancount").to_a[0][0] > 0
2812+
rescue
2813+
false
2814+
end
2815+
end
2816+
end

0 commit comments

Comments
 (0)