]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Don't compare scale if Numeric has no precision
authorpg3-ivan <ivan.melnychuk@pg3.ch>
Fri, 25 Aug 2017 14:02:31 +0000 (10:02 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 28 Aug 2017 22:25:33 +0000 (18:25 -0400)
Fixed bug where comparison of ``Numeric`` types would produce
a difference if the Python-side ``Numeric`` inadvertently specified
a non-None "scale" with a "precision" of None, even though this ``Numeric``
type will pass over the "scale" argument when rendering. Pull request
courtesy Ivan Mmelnychuk.

Change-Id: I0a676e01579fdf6802bf53ea7f9238003da98847
Pull-request: https://bitbucket.org/zzzeek/alembic/pull-requests/70

alembic/ddl/impl.py
docs/build/unreleased/numeric_comparison.rst [new file with mode: 0644]
tests/test_autogen_diffs.py

index 39558ab4b26383a73b01f13bb50a44307a0f035c..ec170fd09de2864dbead4126c9ffbe71ec12da78 100644 (file)
@@ -333,15 +333,14 @@ def _string_compare(t1, t2):
 
 
 def _numeric_compare(t1, t2):
-    return \
-        (
-            t1.precision is not None and
-            t1.precision != t2.precision
-        ) or \
-        (
-            t1.scale is not None and
-            t1.scale != t2.scale
-        )
+    return (
+        t1.precision is not None and
+        t1.precision != t2.precision
+    ) or (
+        t1.precision is not None and
+        t1.scale is not None and
+        t1.scale != t2.scale
+    )
 
 
 def _integer_compare(t1, t2):
diff --git a/docs/build/unreleased/numeric_comparison.rst b/docs/build/unreleased/numeric_comparison.rst
new file mode 100644 (file)
index 0000000..3e2edfa
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, autogenerate
+    :pullreq: bitbucket:70
+
+    Fixed bug where comparison of ``Numeric`` types would produce
+    a difference if the Python-side ``Numeric`` inadvertently specified
+    a non-None "scale" with a "precision" of None, even though this ``Numeric``
+    type will pass over the "scale" argument when rendering. Pull request
+    courtesy Ivan Mmelnychuk.
index e01d631aff888d1953e5dc09bbc9343520016d9a..db77d7451d9bedc1726315026e2a2a697db8427f 100644 (file)
@@ -638,6 +638,13 @@ class CompareTypeSpecificityTest(TestBase):
         is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
         is_(impl.compare_type(Column('x', t3), Column('x', t4)), True)
 
+    def test_numeric_noprecision(self):
+        t1 = Numeric()
+        t2 = Numeric(scale=5)
+
+        impl = self._fixture()
+        is_(impl.compare_type(Column('x', t1), Column('x', t2)), False)
+
     def test_integer(self):
         t1 = Integer()
         t2 = SmallInteger()