Re: [Sqlalchemy-tickets] [sqlalchemy] #2916: possible numeric regression on 0.9.1
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2014-01-21 18:15:11
|
#2916: possible numeric regression on 0.9.1
-----------------------------------+-------------------------------
Reporter: zzzeek | Owner:
Type: defect | Status: closed
Priority: highest | Milestone: 0.9.xx
Component: mssql | Severity: major - 1-3 hours
Resolution: worksforme | Keywords:
Progress State: completed/closed |
-----------------------------------+-------------------------------
Changes (by zzzeek):
* status: new => closed
* resolution: => worksforme
* status_field: in queue => completed/closed
Comment:
this is due to the column being actually DECIMAL on the DB side. the
MSSQL dialect in 0.9 specifically has a pyodbc float type and it does not
check for a type handler. We can check for pyodbc sending us the
"Decimal" class here in the result processor; some dialects, like that of
psycopg2, are smart enough to look at the incoming "coltype" to determine
the correct handling, while others (most?) are not (e.g. MySQLdb sends us
integer codes but we don't have a lookup for them).
So in this case the behavior of using a Float to receive Numeric/DECIMAL
values is undefined; it will vary by backend. In MSSQL's case it's just
changed. I'd rather not get into trying to support mismatches like this
consistently in all cases, it's better to just use the correct type.
here's a test just for record:
{{{
#!python
import sys
import cdecimal
sys.modules["decimal"] = cdecimal
from sqlalchemy import *
e = create_engine("mssql://scott:tiger@ms_2005", echo='debug')
conn = e.connect()
trans = conn.begin()
t = Table('t', MetaData(), Column('data', Numeric(10, 5)))
t.create(conn)
conn.execute(t.insert().values(data="45.17"))
t2 = Table('t', MetaData(), Column('data', Float()))
print(conn.execute(t2.select()).fetchall())
t3 = Table('t', MetaData(), Column('data', Numeric(asdecimal=False)))
print(conn.execute(t3.select()).fetchall())
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2916#comment:2>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|