]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Coerce to float for Float with all native decimal backends
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Jun 2017 20:50:24 +0000 (16:50 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Jun 2017 20:50:24 +0000 (16:50 -0400)
The result processor for the :class:`.Float` type now unconditionally
runs values through the ``float()`` processor if the dialect
specifies that it also supports "native decimal" mode.  While most
backends will deliver Python ``float`` objects for a floating point
datatype, the MySQL backends in some cases lack the typing information
in order to provide this and return ``Decimal`` unless the float
conversion is done.

Change-Id: I638f1480fb00a507036efaf0e0080f26893d98ad
Fixes: #4020
doc/build/changelog/changelog_12.rst
doc/build/changelog/migration_12.rst
lib/sqlalchemy/sql/sqltypes.py
lib/sqlalchemy/testing/suite/test_types.py

index 043f5f1ac287f9cf33fba39ee9562d2639b9e87c..7060d04dbff599f1414314e315aa8179c296b1f5 100644 (file)
 
             :ref:`change_floats_12`
 
+    .. change:: 4020
+        :tags: bug, sql, mysql
+        :tickets: 4020
+
+        The result processor for the :class:`.Float` type now unconditionally
+        runs values through the ``float()`` processor if the dialect
+        specifies that it also supports "native decimal" mode.  While most
+        backends will deliver Python ``float`` objects for a floating point
+        datatype, the MySQL backends in some cases lack the typing information
+        in order to provide this and return ``Decimal`` unless the float
+        conversion is done.
+
+        .. seealso::
+
+            :ref:`change_floats_12`
+
     .. change:: 4017
         :tags: bug, sql
         :tickets: 4017
index a1aeaf1f24e0fa5e5417199982d931ee31d9b95f..b5594f07ceae79806e58425da5a68981b835190d 100644 (file)
@@ -801,9 +801,18 @@ if the application is working with plain floats.
     expr = column('a', Integer) * column('b', Float())
     assert isinstance(expr.type, Float)
 
+* The :class:`.Float` datatype will apply the ``float()`` processor to
+  result values unconditionally if the DBAPI is known to support native
+  ``Decimal()`` mode.  Some backends do not always guarantee that a floating
+  point number comes back as plain float and not precision numeric such
+  as MySQL.
 
 :ticket:`4017`
 
+:ticket:`4018`
+
+:ticket:`4020`
+
 Key Behavioral Changes - ORM
 ============================
 
index 5b53f390eddc1b2dcb1fc9c1e0d9cae6043584f7..6838baa5f1df55a1658b32ba6e30793ee7984312 100644 (file)
@@ -702,6 +702,8 @@ class Float(Numeric):
             return processors.to_decimal_processor_factory(
                 decimal.Decimal,
                 self._effective_decimal_return_scale)
+        elif dialect.supports_native_decimal:
+            return processors.to_float
         else:
             return None
 
index de32e77a4ce71de07bdcaf3a1e31d9d8057210ed..a345454be3952badc9627f301c0b201443e8a713 100644 (file)
@@ -431,7 +431,6 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
             filter_=lambda n: n is not None and round(n, 5) or None
         )
 
-    @testing.fails_on("mysql", "until we do #4020")
     def test_float_coerce_round_trip(self):
         expr = 15.7563