Skip to content

Commit b5e5fad

Browse files
authored
Merge pull request rails#46108 from adrianna-chang-shopify/ac-retry-on-quote-string
Use `#with_raw_connection` in `#quote_string` to retry connection errors
2 parents 364939c + b00ca21 commit b5e5fad

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

activerecord/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Use connection from `#with_raw_connection` in `#quote_string`.
2+
3+
This ensures that the string quoting is wrapped in the reconnect and retry logic
4+
that `#with_raw_connection` offers.
5+
6+
*Adrianna Chang*
7+
18
* Add `expires_in` option to `signed_id`.
29

310
*Shouichi Kamiya*

activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ def error_number(exception)
9797
# QUOTING ==================================================
9898
#++
9999

100+
# Quotes strings for use in SQL input.
100101
def quote_string(string)
101-
any_raw_connection.escape(string)
102-
rescue Mysql2::Error => error
103-
raise translate_exception(error, message: error.message, sql: "<escape>", binds: [])
102+
with_raw_connection(allow_retry: true, uses_transaction: false) do |connection|
103+
connection.escape(string)
104+
end
104105
end
105106

106107
#--

activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def quote(value) # :nodoc:
4343

4444
# Quotes strings for use in SQL input.
4545
def quote_string(s) # :nodoc:
46-
valid_raw_connection.escape(s)
46+
with_raw_connection(allow_retry: true, uses_transaction: false) do |connection|
47+
connection.escape(s)
48+
end
4749
end
4850

4951
# Checks the following cases:

0 commit comments

Comments
 (0)