Render one CHECK for each StrEnum and Literal column - #740
Merged
Merged
Conversation
czpython
force-pushed
the
commonzenpython/one-check-per-choice-column
branch
from
September 27, 2026 17:38
6ea72e2 to
533058c
Compare
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.
With SQLAlchemy 2.1,
druks makemigrationsrenders the CHECK of a StrEnum or Literal column two more times, as explicitsa.CheckConstraintentries inop.create_table. The column'ssa.Enum(..., create_constraint=True)already creates that CHECK. When you apply the revision, each column gets three CHECKs. For a StrEnum, the CHECKs have the same name, so the upgrade fails withDuplicateObject.Alembic finds a CHECK that a type owns through
constraint._create_rule.target. SQLAlchemy 2.1 changed_create_ruleto afunctools.partial, which has notarget. The platformrender_itemhook now skips each CHECK that has_type_boundset, so only the column type creates the CHECK. A CHECK that a model declares in__table_args__still renders.A new test renders the
create_tableop for a StrEnum column and a Literal column through the hook, and asserts that the output has noCheckConstraint.