Skip to content

Commit 69b4ea0

Browse files
committed
Exist queries are retryable
1 parent 43737b8 commit 69b4ea0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ def with_marshable_time_defaults
19711971
# Revert changes
19721972
@connection.change_column_default(:sst_datatypes, :datetime, current_default) if current_default.present?
19731973
end
1974-
1974+
19751975
# We need to give the full paths for this to work.
19761976
undef_method :schema_dump_5_1_path
19771977
def schema_dump_5_1_path
@@ -2796,3 +2796,14 @@ def test_with_recursive_coerced
27962796
end
27972797
end
27982798

2799+
module ActiveRecord
2800+
class AdapterConnectionTest < ActiveRecord::TestCase
2801+
# Original method defined for core adapters.
2802+
undef_method :raw_transaction_open?
2803+
def raw_transaction_open?(connection)
2804+
connection.instance_variable_get(:@raw_connection).query("SELECT @@trancount").to_a[0][0] > 0
2805+
rescue
2806+
false
2807+
end
2808+
end
2809+
end

0 commit comments

Comments
 (0)