From: Mike Bayer Date: Wed, 15 Aug 2018 20:36:30 +0000 (-0400) Subject: Add test support for #4036 X-Git-Tag: rel_1_3_0b1~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a5be7bb92de692c13215ea9b336c831400d5a5e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add test support for #4036 Add a test that asserts MySQL can't implicitly treat a decimal bound parameter without context and everyone else can. Change-Id: I40e24a463d6eb03fd677195895891e73624776c3 --- diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 19d80e0286..2a5262e4ec 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -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 diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 04e0b3b23a..27c7bb115c 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -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): diff --git a/test/requirements.py b/test/requirements.py index 1d11cea470..db6466f220 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -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(