Skip to content

Commit 0339448

Browse files
committed
Fix more double logging in ActiveRecord::QueryLogs
ref: rails#46279 That PR missed the case where if you set `config.active_record.query_log_tags = [:namespaced_controller]`, it would log the controller twice: ``` /*namespaced_controller:Foo::BarController,controller:bar* ``` So this PR just fixes that bug, and tweaks the changelog entry rather than adding another one for the same bug.
1 parent 87bfded commit 0339448

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

actionpack/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
*Andy Waite*
44

5-
* Don't double log the `controller` or `action` when using `ActiveRecord::QueryLog`
5+
* Don't double log the `controller`, `action`, or `namespaced_controller` when using `ActiveRecord::QueryLog`
66

77
Previously if you set `config.active_record.query_log_tags` to an array that included
8-
`:controller` or `:action`, that item would get logged twice. This bug has been fixed.
8+
`:controller`, `:namespaced_controller`, or `:action`, that item would get logged twice.
9+
This bug has been fixed.
910

1011
*Alex Ghiculescu*
1112

actionpack/lib/action_controller/railtie.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class Railtie < Rails::Railtie # :nodoc:
116116
app.config.action_controller.log_query_tags_around_actions
117117

118118
if query_logs_tags_enabled
119-
app.config.active_record.query_log_tags |= [:controller, :action]
119+
app.config.active_record.query_log_tags |= [:controller] unless app.config.active_record.query_log_tags.include?(:namespaced_controller)
120+
app.config.active_record.query_log_tags |= [:action]
120121

121122
ActiveSupport.on_load(:active_record) do
122123
ActiveRecord::QueryLogs.taggings.merge!(

railties/test/application/query_logs_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ def app
127127
assert_match(/\/\*action='index',controller='users',pid='\d+'\*\//, comment)
128128
end
129129

130+
test "namespace controller tags are not doubled up if already configured" do
131+
add_to_config "config.active_record.query_log_tags_enabled = true"
132+
add_to_config "config.active_record.query_log_tags = [ :action, :job, :namespaced_controller, :pid ]"
133+
134+
boot_app
135+
136+
get "/"
137+
comment = last_response.body.strip
138+
139+
assert_match(/\/\*action='index',namespaced_controller='UsersController',pid='\d+'\*\//, comment)
140+
end
141+
130142
test "job perform method has tagging filters enabled by default" do
131143
add_to_config "config.active_record.query_log_tags_enabled = true"
132144

0 commit comments

Comments
 (0)