[Sqlalchemy-tickets] Issue #3096: Misnamed datetime attributes in mysql/base.py (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Tara A. <iss...@bi...> - 2014-06-25 09:05:26
|
New issue 3096: Misnamed datetime attributes in mysql/base.py https://bitbucket.org/zzzeek/sqlalchemy/issue/3096/misnamed-datetime-attributes-in-mysql Tara Andrews: Using SQLAlchemy with a DateTime column on MySQL gives me the following stack trace: ``` #!pycon Traceback (most recent call last): File "/Users/tla/Projects/PBW/main.py", line 9, in <module> our_people = session.query(data.Person).filter_by(name="Alexios").all() File "/Users/tla/anaconda/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2279, in all return list(self) File "/Users/tla/anaconda/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 72, in instances rows = [process[0](row, None) for row in fetch] File "/Users/tla/anaconda/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 451, in _instance populate_state(state, dict_, row, isnew, only_load_props) File "/Users/tla/anaconda/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 305, in populate_state populator(state, dict_, row) File "/Users/tla/anaconda/lib/python2.7/site-packages/sqlalchemy/orm/strategies.py", line 154, in fetch_col dict_[key] = row[col] File "/Users/tla/anaconda/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 769, in process microseconds = value.microseconds AttributeError: 'datetime.datetime' object has no attribute 'microseconds' ``` ...which makes sense, as indeed the attribute is called 'microsecond' and, on the following line, it should be 'second' rather than 'seconds'. Here is the very simple patch: ``` #!diff --- base.py 2014-06-25 11:03:02.000000000 +0200 +++ /Users/tla/anaconda/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py 2014-06-25 11:03:08.000000000 +0200 @@ -766,8 +766,8 @@ def process(value): # convert from a timedelta value if value is not None: - microseconds = value.microseconds - seconds = value.seconds + microseconds = value.microsecond + seconds = value.second minutes = seconds // 60 return time(minutes // 60, minutes % 60, ``` |