Mongoengine: can't compare offset-naive and offset-aware datetimes

Created on 21 Apr 2013  路  5Comments  路  Source: MongoEngine/mongoengine

Can't compare offset-naive and offset-aware datetimes when doing a __set__ because of the comparison of types.

Most helpful comment

Django 1.5.1 uses time-zone-aware datetime objects by default (https://docs.djangoproject.com/en/dev/topics/i18n/timezones/).

You should tell MongoEngine to do the same in the connect call:

mongoengine.connect(db_name, tz_aware=settings.USE_TZ)

All 5 comments

Django 1.5.1 uses time-zone-aware datetime objects by default (https://docs.djangoproject.com/en/dev/topics/i18n/timezones/).

You should tell MongoEngine to do the same in the connect call:

mongoengine.connect(db_name, tz_aware=settings.USE_TZ)

Having the same problem here, using django 1.3.3 and pytz.

here is some exact info:

it happens on BaseField class in the __set__ function when the comparison is between a datefield from the instance._data and a datefield with a timezone that comes in with the value variable.

maybe adding a try/except would be a good idea in case something like that happens with other type of fields.

@ncortot thanks it solved my problem.

Fixed in 0.8 branch

Was this page helpful?
0 / 5 - 0 ratings