1. Michael Bayer
  2. alembic
  3. Issues


Issue #142 resolved

workaround for SQLAlchemy ticket #2825

Michael Bayer
repo owner created an issue


something like this:

diff --git a/alembic/autogenerate/compare.py b/alembic/autogenerate/compare.py
index 17324d8..46c7985 100644
--- a/alembic/autogenerate/compare.py
+++ b/alembic/autogenerate/compare.py
@@ -251,15 +251,15 @@ def _compare_indexes(schema, tname, object_filters, conn_table,
         conn_exps = [exp.name for exp in conn_index.expressions]
         meta_exps = [exp.name for exp in meta_index.expressions]

-        if meta_index.unique is not conn_index.unique \
+        if (meta_index.unique or False) is not conn_index.unique \
                 or meta_exps != conn_exps:
             diffs.append(("remove_index", conn_index))
             diffs.append(("add_index", meta_index))

             msg = []
-            if meta_index.unique is not conn_index.unique:
+            if (meta_index.unique or False) is not conn_index.unique:
                 msg.append(' unique=%r to unique=%r' % (
-                    conn_index.unique, meta_index.unique
+                    conn_index.unique, (meta_index.unique or False)
             if meta_exps != conn_exps:
                 msg.append(' columns %r to %r' % (

Comments (12)

  1. Martin Geisler

    The change first looked strange and unnecessary to me since

    bool(x or False) == bool(x)

    So would

    if bool(meta_index.unique) is not conn_index.unique \

    not be clearer? To my eyes, that expresses more directly that you need to evaluate the truth value of meta_index.unique.

  2. Jameson Lee

    that was me :3

    from debugging provided tests I noticed that it's possible for conn_index.unique to be 0,

    so I'd say wrap both meta_index.unique and conn_index.unique as bool()

    >>> False is not 0
  3. Jameson Lee

    this is from when I run the test using python 2.7 on OSX, and

    $ python setup.py test
    ... blah blah blah ...
    alembic.autogenerate.compare: INFO: Detected changed index 'order_user_id_amount_idx' on 'order': unique=0 to unique=True

    and then the test break (I believe because unique=True is no longer supported for autogeneration)

  4. Log in to comment