]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Ensure scale param not sent to float types
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 6 Mar 2019 14:05:23 +0000 (09:05 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 6 Mar 2019 14:06:04 +0000 (09:06 -0500)
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

doc/build/changelog/unreleased_13/4525.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/base.py
test/dialect/mssql/test_reflection.py

diff --git a/doc/build/changelog/unreleased_13/4525.rst b/doc/build/changelog/unreleased_13/4525.rst
new file mode 100644 (file)
index 0000000..d5b6282
--- /dev/null
@@ -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.
index 49410114029382ddc29dde240dd95b945a6dd660..2d883309d190d1f88b8f54c81a830a0a90327ac1 100644 (file)
@@ -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,
index 29df8706805cad559d8c3749c16d9e626498ed50..d9b65d4e0ab7bd7f82bd1c74d2588ca8005ab314 100644 (file)
@@ -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