]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Adjust for Variant returning itself as impl
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 2 Jun 2017 14:20:27 +0000 (10:20 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 2 Jun 2017 14:32:08 +0000 (10:32 -0400)
Fixed bug where autogen comparison of a :class:`.Variant` datatype
would not compare to the dialect level type for the "default"
implementation of the :class:`.Variant`, returning the type as changed
between database and table metadata.

Change-Id: Ie94779ece9f1c768375cdbdc4124c98f9c11bb86
Fixes: #433
alembic/ddl/impl.py
alembic/testing/requirements.py
alembic/util/__init__.py
alembic/util/sqla_compat.py
docs/build/changelog.rst
tests/test_autogen_diffs.py

index 0971c216f37b4822a26c8cb537011d71f6b54648..39558ab4b26383a73b01f13bb50a44307a0f035c 100644 (file)
@@ -240,6 +240,8 @@ class DefaultImpl(with_metaclass(ImplMeta)):
         metadata_type = metadata_column.type
 
         metadata_impl = metadata_type.dialect_impl(self.dialect)
+        if isinstance(metadata_impl, sqltypes.Variant):
+            metadata_impl = metadata_impl.impl.dialect_impl(self.dialect)
 
         # work around SQLAlchemy bug "stale value for type affinity"
         # fixed in 0.7.4
index 4468ef202687130c1315fbd6b44e991a38a0f325..38527720fb19455f0014a330890635677a0d60b7 100644 (file)
@@ -153,6 +153,13 @@ class SuiteRequirements(Requirements):
             "SQLAlchemy 0.9.4 or greater required"
         )
 
+    @property
+    def sqlalchemy_1014(self):
+        return exclusions.skip_if(
+            lambda config: not util.sqla_1014,
+            "SQLAlchemy 1.0.14 or greater required"
+        )
+
     @property
     def sqlalchemy_110(self):
         return exclusions.skip_if(
index bb249dc6d102273f2f09a3b571130a310dbd2167..8a857366720d428b7f07a1f2b995fb0df96bf75c 100644 (file)
@@ -8,7 +8,7 @@ from .pyfiles import (  # noqa
     pyc_file_from_path, load_python_file, edit)
 from .sqla_compat import (  # noqa
     sqla_07, sqla_079, sqla_08, sqla_083, sqla_084, sqla_09, sqla_092,
-    sqla_094, sqla_099, sqla_100, sqla_105, sqla_110, sqla_1010)
+    sqla_094, sqla_099, sqla_100, sqla_105, sqla_110, sqla_1010, sqla_1014)
 from .exc import CommandError
 
 
index 57eacd511718e852a63598469117f59a5cb696a2..e0507f89e27f7010576449c4d8c09b1653dd5bec 100644 (file)
@@ -30,6 +30,7 @@ sqla_100 = _vers >= (1, 0, 0)
 sqla_105 = _vers >= (1, 0, 5)
 sqla_1010 = _vers >= (1, 0, 10)
 sqla_110 = _vers >= (1, 1, 0)
+sqla_1014 = _vers >= (1, 0, 14)
 
 if sqla_08:
     from sqlalchemy.sql.expression import TextClause
index 9a4b152c379e9db9cf33f41b3bd92cffbf6b1439..4b7a57d742331fe5ee1e2760d32eaf6824868577 100644 (file)
@@ -7,6 +7,15 @@ Changelog
     :version: 0.9.3
     :released:
 
+    .. change:: 433
+      :tags: bug, autogenerate
+      :tickets: 433
+
+      Fixed bug where autogen comparison of a :class:`.Variant` datatype
+      would not compare to the dialect level type for the "default"
+      implementation of the :class:`.Variant`, returning the type as changed
+      between database and table metadata.
+
     .. change:: 431
       :tags: bug, tests
       :tickets: 431
index 239e31fa61f5c265f36a409a0b387ed4e374983e..39329ccfd3e1f8dfdf03fb4424a9a040b5f81a29 100644 (file)
@@ -662,6 +662,46 @@ class CompareTypeSpecificityTest(TestBase):
         is_(impl.compare_type(Column('x', t2), Column('x', t3)), True)
 
 
+class AutogenerateVariantCompareTest(AutogenTest, TestBase):
+    __backend__ = True
+
+    # 1.0.13 and lower fail on Postgresql due to variant / bigserial issue
+    # #3739
+
+    __requires__ = ('sqlalchemy_1014', )
+
+    @classmethod
+    def _get_db_schema(cls):
+        m = MetaData()
+
+        Table('sometable', m,
+              Column(
+                  'id',
+                  BigInteger().with_variant(Integer, "sqlite"),
+                  primary_key=True),
+              Column('value', String(50)))
+        return m
+
+    @classmethod
+    def _get_model_schema(cls):
+        m = MetaData()
+
+        Table('sometable', m,
+              Column(
+                  'id',
+                  BigInteger().with_variant(Integer, "sqlite"),
+                  primary_key=True),
+              Column('value', String(50)))
+        return m
+
+    def test_variant_no_issue(self):
+        uo = ops.UpgradeOps(ops=[])
+        autogenerate._produce_net_changes(self.autogen_context, uo)
+
+        diffs = uo.as_diffs()
+        eq_(diffs, [])
+
+
 class AutogenerateCustomCompareTypeTest(AutogenTest, TestBase):
     __only_on__ = 'sqlite'