[Sqlalchemy-tickets] Issue #4017: float should coerce to Float (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2017-06-23 03:23:00
|
New issue 4017: float should coerce to Float https://bitbucket.org/zzzeek/sqlalchemy/issues/4017/float-should-coerce-to-float Michael Bayer: it seems to be ancient history that we slowly added support for Decimal, but never changed the coercion of plain "float" to be Float, not Numeric w/ decimals: ``` #!python _type_map = { int: Integer(), float: Numeric(), bool: BOOLEANTYPE, decimal.Decimal: Numeric(), dt.date: Date(), dt.datetime: DateTime(), dt.time: Time(), dt.timedelta: Interval(), util.NoneType: NULLTYPE } ``` So the more expensive Decimal is added into situations where plain float is used, and also on SQLite we of course get the warning as well as the wrong type back: ``` #!python from sqlalchemy import create_engine, literal, select e = create_engine("sqlite://") print repr(e.scalar(select([literal(4.56)]))) ``` ``` #! $ python test.py /home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:596: SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage. 'storage.' % (dialect.name, dialect.driver)) Decimal('4.5600000000') ``` ouch! this is easy to fix, but may or may not have hard implications for current applications. Consider for 1.2 if possible. |