Change to mssql datetime implementation breaks times in dates

Issue #923 resolved
Former user created an issue

Reading the history, it looks like the change in r3964 breaks datetime handling. I have a field that's a MSDateTime_pyodbc, and I assign it the value of datetime.datetime.now(), but when I commit it to the database, the time portion of the datetime isn't stored.

nr.respondent_date datetime.datetime(2008, 1, 6, 23, 6, 35, 961000) nr.flush() 2008-01-06 23:07:04,585 INFO sqlalchemy.engine.base.Engine.0x..90 BEGIN INFO:sqlalchemy.engine.base.Engine.0x..90:BEGIN 2008-01-06 23:07:04,585 INFO sqlalchemy.engine.base.Engine.0x..90 INSERT INTO respondent (participant_category_id, respondent_date) VALUES (?, ?); select scope_identity() INFO:sqlalchemy.engine.base.Engine.0x..90:INSERT INTO respondent (participant_category_id, respondent_date) VALUES (?, ?); select scope_identity() 2008-01-06 23:07:04,585 INFO sqlalchemy.engine.base.Engine.0x..90 datetime.datetime(2008, 1, 6, 0, 0) INFO:sqlalchemy.engine.base.Engine.0x..90:datetime.datetime(2008, 1, 6, 0, 0) 2008-01-06 23:07:04,618 INFO sqlalchemy.engine.base.Engine.0x..90 COMMIT INFO:sqlalchemy.engine.base.Engine.0x..90:COMMIT

Looking into mssql.py, I see that in MSDateTime_pyodbc.bind_processor.process, there is a test:

isinstance( value, datetime.date )

But you'll note that this is true if value is a datetime.date or value is a datetime.datetime.

I suspect this is because datetime.date is a superclass of datetime.datetime.

I was able to fix this unwanted behavior by changing the isinstance call to: "type(value) is datetime.date".

Please fix this for the next release.

Thanks, Jason

Comments (3)

  1. Log in to comment