]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add test support for #4036
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 15 Aug 2018 20:36:30 +0000 (16:36 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Aug 2018 17:38:33 +0000 (13:38 -0400)
Add a test that asserts MySQL can't implicitly treat a decimal
bound parameter without context and everyone else can.

Change-Id: I40e24a463d6eb03fd677195895891e73624776c3

lib/sqlalchemy/testing/requirements.py
lib/sqlalchemy/testing/suite/test_types.py
test/requirements.py

index 19d80e02862c35ab8922c0aacc82f49df1e04ca6..2a5262e4ec0783bda3fe860b1862effe34c7f8de 100644 (file)
@@ -628,6 +628,27 @@ class SuiteRequirements(Requirements):
         """
         return exclusions.closed()
 
+    @property
+    def implicit_decimal_binds(self):
+        """target backend will return a selected Decimal as a Decimal, not
+        a string.
+
+        e.g.::
+
+            expr = decimal.Decimal("15.7563")
+
+            value = e.scalar(
+                select([literal(expr)])
+            )
+
+            assert value == expr
+
+        See :ticket:`4036`
+
+        """
+
+        return exclusions.open()
+
     @property
     def nested_aggregates(self):
         """target database can select an aggregate from a subquery that's
index 04e0b3b23a55862d08b2aeed97743353bb060921..27c7bb115c75d56377e1ec90cfc19c6df1a7ab2f 100644 (file)
@@ -483,14 +483,27 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
         )
         eq_(val, expr)
 
-    # TODO: this one still breaks on MySQL
-    # def test_decimal_coerce_round_trip(self):
-    #    expr = decimal.Decimal("15.7563")
-    #
-    #    val = testing.db.scalar(
-    #        select([literal(expr)])
-    #    )
-    #    eq_(val, expr)
+    # this does not work in MySQL, see #4036, however we choose not
+    # to render CAST unconditionally since this is kind of an edge case.
+
+    @testing.requires.implicit_decimal_binds
+    @testing.emits_warning(r".*does \*not\* support Decimal objects natively")
+    def test_decimal_coerce_round_trip(self):
+        expr = decimal.Decimal("15.7563")
+
+        val = testing.db.scalar(
+            select([literal(expr)])
+        )
+        eq_(val, expr)
+
+    @testing.emits_warning(r".*does \*not\* support Decimal objects natively")
+    def test_decimal_coerce_round_trip_w_cast(self):
+        expr = decimal.Decimal("15.7563")
+
+        val = testing.db.scalar(
+            select([cast(expr, Numeric(10, 4))])
+        )
+        eq_(val, expr)
 
     @testing.requires.precision_numerics_general
     def test_precision_decimal(self):
index 1d11cea4706ca37ccdaa490ec5fb9ef74f4c4f3a..db6466f220a38acb0f48ded08a059a72362f90f6 100644 (file)
@@ -923,6 +923,27 @@ class DefaultRequirements(SuiteRequirements):
              'postgresql+psycopg2cffi has FP inaccuracy even with '
              'only four decimal places ')])
 
+    @property
+    def implicit_decimal_binds(self):
+        """target backend will return a selected Decimal as a Decimal, not
+        a string.
+
+        e.g.::
+
+            expr = decimal.Decimal("15.7563")
+
+            value = e.scalar(
+                select([literal(expr)])
+            )
+
+            assert value == expr
+
+        See :ticket:`4036`
+
+        """
+
+        return exclusions.fails_on("mysql+mysqldb", "driver specific")
+
     @property
     def fetch_null_from_numeric(self):
         return skip_if(