From: pg3-ivan Date: Fri, 25 Aug 2017 14:02:31 +0000 (-0400) Subject: Don't compare scale if Numeric has no precision X-Git-Tag: rel_0_9_6~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fb22863a80a5bad8c906e4655c502953cb3490c;p=thirdparty%2Fsqlalchemy%2Falembic.git Don't compare scale if Numeric has no precision 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 --- diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py index 39558ab4..ec170fd0 100644 --- a/alembic/ddl/impl.py +++ b/alembic/ddl/impl.py @@ -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 index 00000000..3e2edfaf --- /dev/null +++ b/docs/build/unreleased/numeric_comparison.rst @@ -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. diff --git a/tests/test_autogen_diffs.py b/tests/test_autogen_diffs.py index e01d631a..db77d745 100644 --- a/tests/test_autogen_diffs.py +++ b/tests/test_autogen_diffs.py @@ -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()