[Sqlalchemy-tickets] [sqlalchemy] #2906: Unicode/UnicodeText return str instead of unicode on MySQL
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2014-01-10 19:09:03
|
#2906: Unicode/UnicodeText return str instead of unicode on MySQL-Python 1.2.3
--------------------------+-----------------------------------------
Reporter: stevejohnson | Owner:
Type: defect | Status: new
Priority: medium | Milestone:
Component: mysql | Severity: no triage selected yet
Keywords: | Progress State: awaiting triage
--------------------------+-----------------------------------------
I recently tried to use a `UnicodeText` column and was surprised to find
that it was giving me `str` values. Upgrading MySQL-Python to 1.2.5 (1.2.4
works too) resulted in getting the correct `unicode` values.
Here's a short test script:
{{{#!python
import sqlalchemy
import MySQLdb
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.session import Session
Base = declarative_base()
class DemoTable(Base):
__tablename__ = 'demo_table'
id = sqlalchemy.Column(sqlalchemy.Integer(), primary_key=True)
unicode_text = sqlalchemy.Column(sqlalchemy.UnicodeText())
engine = sqlalchemy.create_engine('mysql://something?charset=utf8')
Base.metadata.create_all(bind=engine)
session = Session(bind=engine)
session.add(DemoTable(unicode_text=u"What a lovely day"))
session.flush()
session.expire_all()
print 'MySQL', session.query(sqlalchemy.func.version()).one()[0]
print 'sqlalchemy', sqlalchemy.__version__
print 'MySQL-Python', MySQLdb.__version__
print type(session.query(DemoTable).first().unicode_text)
}}}
I tested on v0.8.2-v0.9.1. The output below is the same for all except for
the sqlalchemy version number.
{{{
MySQL 5.6.13-2+debphp.org~precise+2
sqlalchemy 0.8.2
MySQL-Python 1.2.3
<type 'str'>
}}}
{{{
MySQL 5.6.13-2+debphp.org~precise+2
sqlalchemy 0.8.2
MySQL-Python 1.2.4
<type 'unicode'>
}}}
{{{
MySQL 5.6.13-2+debphp.org~precise+2
sqlalchemy 0.8.2
MySQL-Python 1.2.5
<type 'unicode'>
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2906>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|