Skip to content

fix(sqlalchemy-bigquery): harden BigQueryIdentifierPreparer escaping - #19197

Draft
julianxu-goog wants to merge 1 commit into
mainfrom
fix/sqlalchemy-bigquery-identifier-preparer
Draft

julianxu-goog wants to merge 1 commit into
mainfrom
fix/sqlalchemy-bigquery-identifier-preparer

Conversation

@julianxu-goog

Copy link
Copy Markdown

Follow-up hardening for BigQueryIdentifierPreparer and FIELD_ILLEGAL_CHARACTERS (building on #19049):

  • Reject ASCII control characters (\x00-\x1f, \x7f) in BigQueryIdentifierPreparer._escape_identifier with sqlalchemy.exc.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 while preserving valid flexible column characters safely inside backticks.

  • Add unit tests covering escape/unescape round-trips, control-character rejection, and format_label sanitization.

  • Ensure the tests and linter pass (nox -s lint, unit-3.14, unit-3.11, cover at 100% statement and branch coverage)

  • Code coverage does not decrease

Fixes internal issue b/581918631

- 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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant