mapper _postfetch error regarding data conversion
Issue #110
resolved
Try this:
from sqlalchemy import *
engine = create_engine('sqlite://filename=:memory:', encoding='latin2')
test = Table('test', engine,
Column('id', Integer, primary_key=True),
Column('txt', Unicode(50)))
test.create()
class Test(object):
pass
assign_mapper(Test, test)
txt = u"\u0160\u0110\u0106\u010c\u017d"
t1 = Test(id=1, txt = txt)
assert t1.txt == txt
objectstore.commit() # this will raise exception at mapper.py(654)
You will get:
File "...\sqlalchemy\mapping\mapper.py", line 654, in _postfetch
if self._getattrbycolumn(obj, c) != params[c.name](c.name):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa9 in position 0: ordinal not in range(128)
_postfetch
fails because _getattrbycolumn
returns unicode and params[c.name](c.name)
contains converted value.
I guess that not only unicode suffers from this line of code. This line is comparing original value (unicode) with converted values which is prepared for database.
Comments (2)
-
Account Deleted -
repo owner - marked as
- changed status to resolved
fixed in changeset:1127
- Log in to comment
I did the following as a temporary workaround:
It allows for this code to pass:
But I'm not entirely satisified because this (less-correct code) will fail:
Even if it passed, value of
t1.txt
would be different after commit().