From: Mike Bayer Date: Wed, 6 Mar 2019 14:05:23 +0000 (-0500) Subject: Ensure scale param not sent to float types X-Git-Tag: rel_1_3_1~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a2011389ab0d3c80cac175b8e35a18413641358;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Ensure scale param not sent to float types Fixed regression in SQL Server reflection due to :ticket:`4393` where the removal of open-ended ``**kw`` from the :class:`.Float` datatype caused reflection of this type to fail due to a "scale" argument being passed. Fixes: #4525 Change-Id: Ief8bb535778055eff2ab0d71660f81e3676390a1 --- diff --git a/doc/build/changelog/unreleased_13/4525.rst b/doc/build/changelog/unreleased_13/4525.rst new file mode 100644 index 0000000000..d5b6282a46 --- /dev/null +++ b/doc/build/changelog/unreleased_13/4525.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, mssql + :tickets: 4525 + + Fixed regression in SQL Server reflection due to :ticket:`4393` where the + removal of open-ended ``**kw`` from the :class:`.Float` datatype caused + reflection of this type to fail due to a "scale" argument being passed. diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 4941011402..2d883309d1 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -876,8 +876,10 @@ class REAL(sqltypes.REAL): __visit_name__ = "REAL" def __init__(self, **kw): - # REAL is a synonym for FLOAT(24) on SQL server - kw["precision"] = 24 + # REAL is a synonym for FLOAT(24) on SQL server. + # it is only accepted as the word "REAL" in DDL, the numeric + # precision value is not allowed to be present + kw.setdefault("precision", 24) super(REAL, self).__init__(**kw) @@ -2523,13 +2525,12 @@ class MSDialect(default.DefaultDialect): ) coltype = sqltypes.NULLTYPE else: - if ( - issubclass(coltype, sqltypes.Numeric) - and coltype is not MSReal - ): - kwargs["scale"] = numericscale + if issubclass(coltype, sqltypes.Numeric): kwargs["precision"] = numericprec + if not issubclass(coltype, sqltypes.Float): + kwargs["scale"] = numericscale + coltype = coltype(**kwargs) cdict = { "name": name, diff --git a/test/dialect/mssql/test_reflection.py b/test/dialect/mssql/test_reflection.py index 29df870680..d9b65d4e0a 100644 --- a/test/dialect/mssql/test_reflection.py +++ b/test/dialect/mssql/test_reflection.py @@ -42,8 +42,10 @@ class ReflectionTest(fixtures.TestBase, ComparesTables, AssertsCompiledSQL): Column("user_name", types.VARCHAR(20), nullable=False), Column("test1", types.CHAR(5), nullable=False), Column("test2", types.Float(5), nullable=False), + Column("test2.5", types.Float(), nullable=False), Column("test3", types.Text()), Column("test4", types.Numeric, nullable=False), + Column("test4.5", types.Numeric(10, 2), nullable=False), Column("test5", types.DateTime), Column( "parent_user_id", @@ -105,6 +107,19 @@ class ReflectionTest(fixtures.TestBase, ComparesTables, AssertsCompiledSQL): def test_money_type(self): self._test_specific_type(mssql.MONEY, "MONEY") + def test_numeric_prec_scale(self): + self._test_specific_type(mssql.NUMERIC(10, 2), "NUMERIC(10, 2)") + + def test_float(self): + self._test_specific_type(mssql.FLOAT, "FLOAT(53)") + + def test_real(self): + self._test_specific_type(mssql.REAL, "REAL") + + def test_float_as_real(self): + # FLOAT(5) comes back as REAL + self._test_specific_type(mssql.FLOAT(5), "REAL") + @testing.provide_metadata def test_identity(self): metadata = self.metadata