Skip to content

fix(django-google-spanner): unconditionally quote all identifiers in quote_name - #19228

Open
PCTEJA wants to merge 1 commit into
googleapis:mainfrom
PCTEJA:fix-django-spanner-quote-name-19072
Open

PCTEJA wants to merge 1 commit into
googleapis:mainfrom
PCTEJA:fix-django-spanner-quote-name-19072

Conversation

@PCTEJA

@PCTEJA PCTEJA commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

DatabaseOperations.quote_name() in django-google-spanner returned valid unreserved regular ASCII identifiers unquoted, so the backend had to track SPANNER_RESERVED_KEYWORDS to decide when quoting was required. This change removes that fast path so all identifiers are escaped and wrapped in backticks as a single identifier.

Fixes #19072

Changes

  • django_spanner/operations.py: remove the _REGULAR_IDENTIFIER_RE / SPANNER_RESERVED_KEYWORDS fast path in quote_name() and the now unused import and regex. Already quoted identifiers are still returned unchanged, the empty string is still returned as is, and the RUNNING_SPANNER_BACKEND_TESTS=1 character replacements still happen before quoting. The OpenTelemetry model_name span attributes in schema.py already pass the unquoted model._meta.db_table (fixed in fix(django-google-spanner): use unquoted table names for OpenTelemetry model_name attributes #19096), and check constraint DDL quoting was fixed in fix(django-google-spanner): fix column check constraint DDL #19070, so no schema change is needed.
  • Update unit and mockserver test expectations that assumed unquoted identifiers (generated query SQL, DDL, THEN RETURN columns, and index STORING columns).

Testing

  • pytest tests/unit tests/mockserver_tests: 223 passed on Django 5.2 (two runs) and 223 passed on Django 6.0.
  • The updated tests fail against the previous quote_name() implementation (84 failures) and pass with this change.
  • Format: ruff format and ruff check --select I (ruff 0.14.14, as pinned in the package noxfile) are clean for the package.

…quote_name

quote_name() returned valid unreserved regular ASCII identifiers
unquoted, which required tracking SPANNER_RESERVED_KEYWORDS. Remove
the fast path so all identifiers are escaped and wrapped in backticks,
and update the unit and mockserver SQL expectations accordingly.

Fixes googleapis#19072

@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 simplifies the identifier quoting logic in django_spanner/operations.py by unconditionally escaping and wrapping all table, index, and column names in backticks. This change removes the need for tracking Spanner's reserved keywords and regular identifiers, leading to the removal of SPANNER_RESERVED_KEYWORDS and _REGULAR_IDENTIFIER_RE. Consequently, numerous test cases across the test suite have been updated to expect backticks around identifiers in the generated SQL. No review comments were provided, and I have no additional feedback to offer as the changes are clean and consistent.

@PCTEJA

PCTEJA commented Nov 27, 2026

Copy link
Copy Markdown
Author

@olavloite could you please look into this, when your free?

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.

chore(django-google-spanner): unconditionally quote all identifiers in quote_name

2 participants