Skip to content
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

activerecord: Allow comment prefix in queries when preventing writes #37184

Merged
merged 1 commit into from Sep 12, 2019

Conversation

dylanahsmith
Copy link
Contributor

@rafaelfranca

Problem

We use marginalia attach comments to queries to help provide context for queries in the slow query log. We also use Marginalia::Comment.prepend_comment = true to prepend the comment so it isn't lost from truncation. However, this resulted in the ActiveRecord::ConnectionAdapters::MySQL::DatabaseStatements::READ_QUERY to no longer match any queries, which would prevent any queries from being performed on a database connection configured with replica: true due to it trying to prevent write queries.

Solution

Update the regex to ignore /* ... */ comments at the start of the query string.

@rafaelfranca rafaelfranca merged commit 12b964c into rails:master Sep 12, 2019
eugeneius pushed a commit that referenced this pull request Apr 13, 2020
activerecord: Allow comment prefix in queries when preventing writes
@eugeneius
Copy link
Member

Backported to 6-0-stable in 290e485.

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.

None yet

3 participants