Skip to content

Comments

Fix duplicate CHECK constraints for Boolean/Enum in batch mode#1793

Open
khanjan2708 wants to merge 3 commits intosqlalchemy:mainfrom
khanjan2708:issue-1768
Open

Fix duplicate CHECK constraints for Boolean/Enum in batch mode#1793
khanjan2708 wants to merge 3 commits intosqlalchemy:mainfrom
khanjan2708:issue-1768

Conversation

@khanjan2708
Copy link

Description

Fixes: #1768

This PR prevents the generation of duplicate CHECK constraints when adding or altering Boolean/Enum columns in batch mode while using a naming convention.

The Fix :

  • Suppresses Implicit Constraints: Explicitly disables automatic type-level CHECK constraint generation during batch migrations to avoid collisions with Alembic's explicit operations.
  • Propagates Conventions: Ensures the temporary metadata used in batch mode inherits the naming convention from the original table.
  • Automatic Defaults: Updates batch_alter_table to automatically pull the naming convention from the migration context.

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

- Suppress automatic type-level events during batch add/alter column
- Inherit naming convention in temporary batch metadata
- Automatically detect naming convention from migration context

Fixes: sqlalchemy#1768
@khanjan2708 khanjan2708 marked this pull request as ready for review February 20, 2026 16:44
Copy link
Member

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

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

thanks for this, please let me know if you want me to finish it up w/ changelog and compat function

existing.type = type_

if isinstance(existing.type, SchemaEventTarget):
existing.type._create_events = ( # type:ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

this seems like a good place for a sqla_compat function. there's not a fixed way to remove the events from a SchemaType and it might change.

@zzzeek zzzeek requested a review from sqla-tester February 20, 2026 19:00
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision f34f0f1 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change f34f0f1: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6602

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.

Boolean create_constraint generating double CHECK

3 participants