Repository navigation
fix(sqlalchemy-bigquery): harden BigQueryIdentifierPreparer escaping - #19197
Draft
julianxu-goog wants to merge 1 commit into
Draft
julianxu-goog wants to merge 1 commit into
julianxu-goog wants to merge 1 commit into
Conversation
- Reject ASCII control characters (\x00-\x1f, \x7f) in BigQueryIdentifierPreparer._escape_identifier with CompileError. - Replace sequential .replace() calls in BigQueryIdentifierPreparer._unescape_identifier with a single-pass regex for \\ and \` escape sequences. - Update FIELD_ILLEGAL_CHARACTERS (used by format_label) to include backticks (`) and all ASCII control characters (\x00-\x1f, \x7f), matching BigQuery's flexible column name specification. - Add unit tests covering escape/unescape round-trips, control-character rejection, and format_label sanitization. Fixes internal issue b/581918631
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the BigQueryIdentifierPreparer to reject control characters in identifiers, raising a CompileError if any are detected. It also refactors the unescaping logic to use a regular expression and updates the illegal characters pattern for fields. Comprehensive unit tests have been added to verify these changes. I have no additional feedback to provide.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up hardening for
BigQueryIdentifierPreparerandFIELD_ILLEGAL_CHARACTERS(building on #19049):Reject ASCII control characters (
\x00-\x1f,\x7f) inBigQueryIdentifierPreparer._escape_identifierwithsqlalchemy.exc.CompileError.Replace sequential
.replace()calls inBigQueryIdentifierPreparer._unescape_identifierwith a single-pass regex for\\and\`escape sequences.Update
FIELD_ILLEGAL_CHARACTERS(used byformat_label) to include backticks (`) and all ASCII control characters (\x00-\x1f,\x7f), matching BigQuery's flexible column name specification while preserving valid flexible column characters safely inside backticks.Add unit tests covering escape/unescape round-trips, control-character rejection, and
format_labelsanitization.Ensure the tests and linter pass (
nox -s lint,unit-3.14,unit-3.11,coverat 100% statement and branch coverage)Code coverage does not decrease
Fixes internal issue b/581918631