Repository navigation
chore(django-google-spanner): enable check constraints on Spanner Emulator #19094
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,10 +136,11 @@ def quote_name(self, name: str) -> str: | |
| backticks, backslashes, or ASCII control characters) are escaped and | ||
| wrapped in backticks as a single identifier. | ||
|
|
||
| Spanner does not allow spaces or hyphens in table or index names, even | ||
| when quoted. Only when running Django's own backend test suite | ||
| (``RUNNING_SPANNER_BACKEND_TESTS=1``) are spaces and hyphens replaced | ||
| with underscores so Django test models that use such names can run. | ||
| Spanner does not allow spaces, hyphens, or '>' in table, index, or | ||
| constraint names, even when quoted. Only when running Django's own | ||
| backend test suite (``RUNNING_SPANNER_BACKEND_TESTS=1``) are those | ||
| characters replaced with underscores so Django test models that use | ||
| such names can run. | ||
|
|
||
| :type name: str | ||
| :param name: The table, index, or column name to quote. | ||
|
|
@@ -154,7 +155,7 @@ def quote_name(self, name: str) -> str: | |
| if not name: | ||
| return name | ||
| if os.environ.get("RUNNING_SPANNER_BACKEND_TESTS") == "1": | ||
| name = name.replace(" ", "_").replace("-", "_") | ||
| name = name.replace(" ", "_").replace("-", "_").replace(">", "_") | ||
|
olavloite marked this conversation as resolved.
Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. " ", "-", and ">" are all tokens that Spanner does not allow in identifiers (e.g. table names or constraint names). Normally, if an application tries to use any of those for a table name or constraint name, then we just send them to Spanner and let Spanner return an error. However, these specific replacements are applied only when running the standard Django tests (the ones defined in Django itself). Previously, we only replaced " " and "-", as those were the only ones that were actually used by those tests. Now that we also run the tests for CHECK constraints, we need to replace ">" as well, as the tests contain a constraint that has the name |
||
| if _QUOTED_IDENTIFIER_RE.match(name): | ||
| return name | ||
| # TODO(https://github.com/googleapis/google-cloud-python/issues/19072): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We support FOREIGN KEY right? It wasn't supported in Emulator before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.cloud.google.com/spanner/docs/foreign-keys/how-to#drop-foreign-key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the emulator supports foreign keys, but this pull request intentionally limits the scope to only fixing CHECK constraints. I've updated the TODO to better explain what the current status is, and added a tracking bug for foreign keys.