Skip to content

Commit 63091d6

Browse files
authored
Merge pull request rails#51551 from ngan/fix-sqlcommenter-key-sort
Allow string keys for SQLCommenter
2 parents 73d692f + 9186dfe commit 63091d6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

activerecord/lib/active_record/query_logs_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize
2828
end
2929

3030
def format(pairs)
31-
pairs.sort_by!(&:first)
31+
pairs.sort_by! { |pair| pair.first.to_s }
3232
super
3333
end
3434

activerecord/test/cases/query_logs_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,23 @@ def test_sqlcommenter_format_value
229229
end
230230
end
231231

232+
def test_sqlcommenter_format_allows_string_keys
233+
ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
234+
235+
ActiveRecord::QueryLogs.tags = [
236+
:application,
237+
{
238+
"string" => "value",
239+
tracestate: "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7",
240+
custom_proc: -> { "Joe's Shack" }
241+
},
242+
]
243+
244+
assert_queries_match(%r{custom_proc='Joe%27s%20Shack',tracestate='congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7',string='value'\*/}) do
245+
Dashboard.first
246+
end
247+
end
248+
232249
def test_sqlcommenter_format_value_string_coercible
233250
ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
234251

0 commit comments

Comments
 (0)