Skip to content

Freeze modifications to ActiveRecord::QueryLogs #52410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Jul 24, 2024

Refs #52404 and #52392

Tags and taggings build a cache when they are assigned, which means we cannot support them being mutated. This freezes tags and taggings to ensure they aren't changed after assignment.

This may not cover all cases, and per the previous PR we intend this to be configured mostly via application.config, but it covers a case we were making in our test suite and so should hopefully cover a mistake users are somewhat likely to make.

@@ -185,7 +185,7 @@ def test_empty_comments_are_not_added

def test_sql_commenter_format
ActiveRecord::QueryLogs.tags_formatter = :sqlcommenter
ActiveRecord::QueryLogs.tags = [:application, {}]
ActiveRecord::QueryLogs.tags = [:application]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change we could remove this line, but I think it's worth setting the value we're testing for

@@ -134,6 +133,7 @@ def tags_formatter=(format) # :nodoc:
else
raise ArgumentError, "Formatter is unsupported: #{format}"
end
@tags_formatter = format
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this setter be here, after @formatter, so that the exception that can be raised above prevents the assignment.

Tags and taggings build a cache when they are assigned, which means we
cannot support them being mutated. This freezes tags and taggings to
ensure they aren't changed after assignment.

This may not cover all cases, and per the previous PR we intend this to
be configured mostly via application.config, but it covers a case we
were making in our test suite and so should hopefully cover a mistake
users are somewhat likely to make.
@jhawthorn jhawthorn force-pushed the freeze_query_logs branch from 69a8417 to 146ae32 Compare July 24, 2024 06:36
Copy link
Member

@byroot byroot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@jhawthorn jhawthorn merged commit 72741db into rails:main Jul 24, 2024
3 checks passed
@jhawthorn jhawthorn deleted the freeze_query_logs branch July 24, 2024 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants