summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-06-02 10:20:27 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-06-02 10:32:08 -0400
commit54c5abb15caeb14ddfc70d54424a59dbf8ef3132 (patch)
tree4a663725fd359282747a7b31109499a2be1d4182
parentc320b4c9b9a3ad5501d9a89329f585bbc6a48446 (diff)
downloadalembic-54c5abb15caeb14ddfc70d54424a59dbf8ef3132.tar.gz
Adjust for Variant returning itself as impl
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
-rw-r--r--alembic/ddl/impl.py2
-rw-r--r--alembic/testing/requirements.py7
-rw-r--r--alembic/util/__init__.py2
-rw-r--r--alembic/util/sqla_compat.py1
-rw-r--r--docs/build/changelog.rst9
-rw-r--r--tests/test_autogen_diffs.py40
6 files changed, 60 insertions, 1 deletions
diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py
index 0971c21..39558ab 100644
--- a/alembic/ddl/impl.py
+++ b/alembic/ddl/impl.py
@@ -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
diff --git a/alembic/testing/requirements.py b/alembic/testing/requirements.py
index 4468ef2..3852772 100644
--- a/alembic/testing/requirements.py
+++ b/alembic/testing/requirements.py
@@ -154,6 +154,13 @@ class SuiteRequirements(Requirements):
)
@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(
lambda config: not util.sqla_110,
diff --git a/alembic/util/__init__.py b/alembic/util/__init__.py
index bb249dc..8a85736 100644
--- a/alembic/util/__init__.py
+++ b/alembic/util/__init__.py
@@ -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
diff --git a/alembic/util/sqla_compat.py b/alembic/util/sqla_compat.py
index 57eacd5..e0507f8 100644
--- a/alembic/util/sqla_compat.py
+++ b/alembic/util/sqla_compat.py
@@ -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
diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst
index 9a4b152..4b7a57d 100644
--- a/docs/build/changelog.rst
+++ b/docs/build/changelog.rst
@@ -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
diff --git a/tests/test_autogen_diffs.py b/tests/test_autogen_diffs.py
index 239e31f..39329cc 100644
--- a/tests/test_autogen_diffs.py
+++ b/tests/test_autogen_diffs.py
@@ -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'