hi all, I'm getting a "TypeError: can't compare offset-naive and 
offset-aware datetimes" when attempting to update a database table value(in 
a celery task), even though I'm pretty sure both dates in question are 
offset-aware.

here is the stack trace of the issue:

[2014-08-02 12:10:52,264: ERROR/MainProcess] Task 
lrd.queue.tasks.fetch_rss_posts[d774aa85-043f-4aaf-928b-94c8a846b33e] 
raised unexpected: TypeError("can't compare offset-naive and offset-aware 
datetimes",)
Traceback (most recent call last):
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/celery-3.1.13-py2.7.egg/celery/app/trace.py",
 
line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/celery-3.1.13-py2.7.egg/celery/app/trace.py",
 
line 437, in __protected_call__
    return self.run(*args, **kwargs)
*  File "/Users/Shared/webapp/lrd_env/lrd/lrd/queue/tasks.py", line 61, in 
fetch_rss_posts*
    feed.latestpost = utc_pub_time
  File "/usr/local/lib/python2.7/site-packages/transaction/_manager.py", 
line 120, in __exit__
    self.commit()
  File "/usr/local/lib/python2.7/site-packages/transaction/_manager.py", 
line 111, in commit
    return self.get().commit()
  File 
"/usr/local/lib/python2.7/site-packages/transaction/_transaction.py", line 
280, in commit
    reraise(t, v, tb)
  File 
"/usr/local/lib/python2.7/site-packages/transaction/_transaction.py", line 
271, in commit
    self._commitResources()
  File 
"/usr/local/lib/python2.7/site-packages/transaction/_transaction.py", line 
417, in _commitResources
    reraise(t, v, tb)
  File 
"/usr/local/lib/python2.7/site-packages/transaction/_transaction.py", line 
389, in _commitResources
    rm.tpc_begin(self)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/zope.sqlalchemy-0.7.5-py2.7.egg/zope/sqlalchemy/datamanager.py",
 
line 90, in tpc_begin
    self.session.flush()
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/session.py",
 
line 1907, in flush
    self._flush(objects)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/session.py",
 
line 2025, in _flush
    transaction.rollback(_capture_exception=True)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py",
 
line 57, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/session.py",
 
line 1989, in _flush
    flush_context.execute()
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py",
 
line 371, in execute
    rec.execute(self)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py",
 
line 524, in execute
    uow
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py",
 
line 54, in save_obj
    table, states_to_update)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py",
 
line 343, in _collect_update_commands
    attributes.PASSIVE_NO_INITIALIZE)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py",
 
line 1387, in get_state_history
    return state.get_history(key, passive)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/state.py",
 
line 264, in get_history
    return self.manager[key].impl.get_history(self, self.dict, passive)
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py",
 
line 661, in get_history
    return History.from_scalar_attribute(self, state, dict_[self.key])
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py",
 
line 1280, in from_scalar_attribute
    elif attribute.is_equal(current, original) is True:
  File 
"/Users/Shared/webapp/lrd_env/lib/python2.7/site-packages/sqlalchemy/sql/type_api.py",
 
line 207, in compare_values
    return x == y
*TypeError: can't compare offset-naive and offset-aware datetimes*


I'm comparing the date of the rss feed items published date with the 
latestpost of the rss feed. I ensure that the dates generated have 
pytz.UTC() added. Note the actual issue happens in line 61 of 
fetch_rss_posts task. Here is the py source of the tasks:

http://pastebin.com/FPNvHLp4

note on line 61 I'm simply doing 
feed.latestpost = utc_pub_time


I generate latestpost in an alembic migration script, of which I'm sure I'm 
adding offset information with pytz.UTC() here is how I generate the 
RssFeed member, latest_post on line 32:

http://pastebin.com/eN2kipVs

Here is some logging:

http://pastebin.com/Vb31bCP6

Another interesting thing is, the issue doesn't actually occur until after 
the rss feed completely parsed.

Any ideas?
Michael

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to