feat: Support Server-Side Checks for Enums#694
Merged
olavloite merged 1 commit intogoogleapis:mainfrom Jun 27, 2025
Merged
Conversation
olavloite
reviewed
Jun 19, 2025
| # Spanner uses protos for enums. Creating a column like | ||
| # Column("an_enum", Enum("A", "B", "C")) will result in a String | ||
| # column. Setting supports_native_enum to False means SQLAlchemy | ||
| # will generate check constraints to enforce the enum values |
Contributor
There was a problem hiding this comment.
I'm not sure this change is enough to actually achieve this. Would you otherwise mind adding a test that shows that it does?
I tried the same here, but it does not seem to make any difference: https://github.com/googleapis/python-spanner-sqlalchemy/pull/698/files
Contributor
Author
There was a problem hiding this comment.
Sorry, I should have added a test here. You need to additionally pass create_constraint=True into the Enum constructor to generate the CHECK constraints. If supports_native_enum=True, it won't actually generate the CHECK constraints when setting create_constraint=True.
Spanner uses protos for enums. Creating a column like
Column("an_enum", Enum("A", "B", "C")) will result in a String
column. Setting supports_native_enum to False allows SQLAlchemy
to generate check constraints to enforce the enum values if the
create_constraint=True flag is passed to the Enum constructor.
Fixes: googleapis#686
olavloite
approved these changes
Jun 27, 2025
aakashanandg
approved these changes
Jun 27, 2025
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.
Spanner uses protos for enums. Creating a column like Column("an_enum", Enum("A", "B", "C", create_constraint=True)) will result in a String column. Setting supports_native_enum to False means SQLAlchemy will generate check constraints to enforce the enum values server-side rather than rely on a the database's native enum type to enforce them.
Fixes: #686