On 06/22/2017 09:18 PM,
phix...@gmail.com wrote:
> Hello,
>
> I get the warning message "SAWarning: Dialect sqlite+pysqlite does *not*
> support Decimal objects natively, and SQLAlchemy must convert from
> floating point", without me using a Decimal object anywhere, which was
> highly confusing.
>
> This occurs when evaluating a hybrid property multiplying an
> sqltypes.Integer column with a python float literal (0.5), which I would
> expect to result in a float.
> It seems to be caused by two weird looking definitions in sqltypes.py:
>
> class Numeric(_DateAffinity, TypeEngine): ...
> def __init__(self, ..., asdecimal=True): ...
>
>
> _type_map = {...
> float: Numeric(), ...
>
>
> Is there a reason, why floats are treated as decimals (instead of binary
> floating points?) by default,
looks like ancient history, where there was only "float: Numeric()", and
then somewhere around the 0.5 series we started also accommodating
Python Decimal objects, so "Decimal: Numeric()" was added, and I didn't
trace it out completely but it's likely that the strict "asdecimal" /
"asfloat" separation evolved later than that. Earlier, it was just
whatever the driver did.
So the float coercion there never changed.
It should be a Float() so
https://bitbucket.org/zzzeek/sqlalchemy/issues/4017/float-should-coerce-to-float
is added.
and a way to prevent this from happening
> when defining the following property?
>
>
> @my_hybrid_property.expression
> def my_hybrid_property(cls):
> return cls.my_integer_column * 0.5
you can set the type explicitly:
from sqlalchemy import literal, Float
return my_col * literal(0.5, Float())
>
>
> Greetings,
>
> Phillip Kuhrt
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
>
http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See
http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
sqlalchemy+...@googlegroups.com
> <mailto:
sqlalchemy+...@googlegroups.com>.
> To post to this group, send email to
sqlal...@googlegroups.com
> <mailto:
sqlal...@googlegroups.com>.
> Visit this group at
https://groups.google.com/group/sqlalchemy.
> For more options, visit
https://groups.google.com/d/optout.