summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-06-22 23:51:52 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-06-26 11:05:38 -0400
commit1776597131ef96472b5188cebc72c31a387c90f4 (patch)
treee158f177c7da7999323175263719216085a616d3 /lib/sqlalchemy
parent83c1e03c5c74c69facfc371840ffae890f05c338 (diff)
downloadsqlalchemy-1776597131ef96472b5188cebc72c31a387c90f4.tar.gz
Coerce float Python type to Float; ensure Python float coming back
Added some extra strictness to the handling of Python "float" values passed to SQL statements. A "float" value will be associated with the :class:`.Float` datatype and not the Decimal-coercing :class:`.Numeric` datatype as was the case before, eliminating a confusing warning emitted on SQLite as well as unecessary coercion to Decimal. Change-Id: I1bb1810ff1d198c0d929ccba5656e55401d74119 Fixes: #4017
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py2
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py18
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index 7a3c50549..06b5e5c19 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -2604,7 +2604,7 @@ MATCHTYPE = MatchType()
_type_map = {
int: Integer(),
- float: Numeric(),
+ float: Float(),
bool: BOOLEANTYPE,
decimal.Decimal: Numeric(),
dt.date: Date(),
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py
index ee757e1ca..de32e77a4 100644
--- a/lib/sqlalchemy/testing/suite/test_types.py
+++ b/lib/sqlalchemy/testing/suite/test_types.py
@@ -431,6 +431,24 @@ 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
+
+ val = testing.db.scalar(
+ select([literal(expr)])
+ )
+ 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)
+
@testing.requires.precision_numerics_general
def test_precision_decimal(self):
numbers = set([