]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Compare to metadata_impl in compare_type() to guard against custom TypeDecorator
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Nov 2016 13:42:12 +0000 (08:42 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Nov 2016 13:47:23 +0000 (08:47 -0500)
Fixed bug where usage of a custom TypeDecorator which returns a
per-dialect type via :meth:`.TypeDecorator.load_dialect_impl` that differs
significantly from the default "impl" for the type decorator would fail
to compare correctly during autogenerate.

Change-Id: I384df35be9513bf8a2ae55e7daa9a52c23108a49
Fixes: #395
alembic/ddl/impl.py
docs/build/changelog.rst
tests/test_autogen_diffs.py

index 56b4d59c9ca065222d3d23d108fdef7b19800e9b..52cc4702f90bcd63ca719334a84f4f3f991c69c4 100644 (file)
@@ -256,7 +256,7 @@ class DefaultImpl(with_metaclass(ImplMeta)):
         ):
             comparator = _type_comparators.get(conn_type._type_affinity, None)
 
-            return comparator and comparator(metadata_type, conn_type)
+            return comparator and comparator(metadata_impl, conn_type)
         else:
             return True
 
index 6c1d7d24539011215b36c3a52cc2022260c5c051..f8a89be2809ac9c0d827bac94e57e39ac6135f12 100644 (file)
@@ -6,6 +6,15 @@ Changelog
 .. changelog::
     :version: 0.8.9
 
+    .. change::
+      :tags: bug, autogenerate
+      :tickets: 395
+
+      Fixed bug where usage of a custom TypeDecorator which returns a
+      per-dialect type via :meth:`.TypeDecorator.load_dialect_impl` that differs
+      significantly from the default "impl" for the type decorator would fail
+      to compare correctly during autogenerate.
+
     .. change::
       :tags: bug, autogenerate, postgresql
       :tickets: 392
index 04c9e9671511c87c3ec66b9742bd51de7159108d..4816134fbc5a46c00bec2ecf10bc167e1af340b8 100644 (file)
@@ -5,7 +5,8 @@ from sqlalchemy import MetaData, Column, Table, Integer, String, Text, \
     TypeDecorator, CheckConstraint, text, PrimaryKeyConstraint, \
     ForeignKeyConstraint, VARCHAR, DECIMAL, DateTime, BigInteger, BIGINT, \
     SmallInteger
-from sqlalchemy.types import NULLTYPE
+from sqlalchemy.dialects import sqlite
+from sqlalchemy.types import NULLTYPE, VARBINARY
 from sqlalchemy.engine.reflection import Inspector
 
 from alembic.operations import ops
@@ -592,6 +593,26 @@ class CompareTypeSpecificityTest(TestBase):
         return impl.DefaultImpl(
             default.DefaultDialect(), None, False, True, None, {})
 
+    def test_typedec_to_nonstandard(self):
+
+        class PasswordType(TypeDecorator):
+            impl = VARBINARY
+
+            def copy(self, **kw):
+                return PasswordType(self.impl.length)
+
+            def load_dialect_impl(self, dialect):
+                if dialect.name == 'default':
+                    impl = sqlite.NUMERIC(self.length)
+                else:
+                    impl = VARBINARY(self.length)
+                return dialect.type_descriptor(impl)
+
+        impl = self._fixture()
+        impl.compare_type(
+            Column('x', sqlite.NUMERIC(50)),
+            Column('x', PasswordType(50)))
+
     def test_string(self):
         t1 = String(30)
         t2 = String(40)