Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For Discussion: Updating Askbot for USE_TZ=True in Django>=1.4

I've been working on integrating Askbot with a commercial product developed in Django 1.5.8. A major sticking point I ran into was the use of timezone-aware datetime objects in the existing product, which cause the "Can't subtract offset-naive and offset-aware datetimes" exception. (I can't post links, but search for it on this forum, and you'll find at least one thread.)

I've created a fix. It was a basically a find-and-replace operation, replacing all instances of datetime.datetime.now() in the code with timezone.now(), and adding an import: from django.utils import timezone. timezone.now() is a Django utility function that returns a timezone-aware or timezone-naive datetime object according to the USE_TZ setting. I also had to update some datetime.datetime instances with a tzinfo attribute, and I had to replace import datetime in all migration scripts with from south.utils import datetime_utils as datetime, which is a South compatibility layer for USE_TZ.

I could contribute this fix back, but it would force dependency updates. Django's timezone module was introduced in Django 1.4, so versions of Django<1.4 would no longer be compatible with Askbot. Versions of South before datetime_utils was introduced would also no longer be compatible. It would be possible to write compatibility patches, eg:

try:
    from django.utils import timezone
except ImportError:
    from askbot.utils import timezone

...but I'm hesitant to do so, because a lot of the work I've had to do in getting Askbot to work in Django 1.5.8 has been undoing or working around prior patches. I would rather contribute work that moves Askbot forward.