Skip to content

False change for unique constraint with case-sensitive names in 1.4.0 #654

@ods

Description

@ods

PostgreSQL, a unique constraint with uppercase letters in name. _compare_indexes_and_uniques takes name as _constraint_sig.name (just the name without quotes) for constraint from connection, but as _constraint_sig.md_name_to_sql_name(context) (gives the name in double quotes) for constraint from metadata. That causes false changes detection with script that drops and creates the same constraint.

The following change solves the problem:

--- a/alembic/autogenerate/compare.py
+++ b/alembic/autogenerate/compare.py
@@ -541,7 +541,7 @@ def _compare_indexes_and_uniques(
     conn_uniques_by_name = dict((c.name, c) for c in conn_unique_constraints)
     conn_indexes_by_name = dict((c.name, c) for c in conn_indexes)
     conn_names = dict(
-        (c.name, c)
+        (c.md_name_to_sql_name(autogen_context), c)
         for c in conn_unique_constraints.union(conn_indexes)
         if c.name is not None
     )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions