First time here? Check out the FAQ!
0

Getting 'can't subtract offset-naive and offset-aware datetimes'

  • retag add tags

At a few places in the codebase, I'm getting the error that I can't subtract offset-naive and offset-aware datetimes. I tried fixing it in one place in the source, but ran into it somewhere else. Any advice?

Environment:


Request Method: GET
Request URL: http://ec2-54-242-211-34.compute-1.amazonaws.com/questions/

Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
('longerusername',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.humanize',
 'django.contrib.sitemaps',
 'django.contrib.messages',
 'askbot',
 'askbot.deps.django_authopenid',
 'south',
 'askbot.deps.livesettings',
 'keyedcache',
 'robots',
 'django_countries',
 'djcelery',
 'djkombu',
 'followit',
 'tinymce',
 'group_messaging',
 'compressor')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
 'askbot.middleware.forum_mode.ForumModeMiddleware',
 'askbot.middleware.cancel.CancelActionMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'askbot.middleware.view_log.ViewLogMiddleware',
 'askbot.middleware.spaceless.SpacelessMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/askbot/views/readers.py" in questions
  235.             'update_avatar_data': schedules.should_update_avatar_data(request),
File "/usr/local/lib/python2.7/dist-packages/askbot/schedules.py" in should_update_avatar_data
  11.         if (datetime.today() - user.last_login).days <= 1:

Exception Type: TypeError at /questions/
Exception Value: can't subtract offset-naive and offset-aware datetimes
yjkogan's avatar
1
yjkogan
asked 2013-04-03 23:49:41 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

Answered my own question.

The default settings.py file created by django-admin.py (at least in django 1.5) sets USE_TZ to True.

Just set USE_TZ to False, or simply remove it from the settings file, since in the absence of a directive the value is assumed to be False.

yjkogan's avatar
1
yjkogan
answered 2013-04-04 01:31:16 -0600
edit flag offensive 0 remove flag delete link

Comments

We've not tested yet Askbot with django 1.5, in fact in the repository version, we've added an upper limit for the django version. Does askbot work for you in 1.5?

Evgeny's avatar Evgeny (2013-04-04 21:16:00 -0600) edit

I think I ran into a different issue with 1.5 specific to installation and had to roll it back in order to get askbot working. However, I initialized the repo with 1.5 b/c they changed the directory format in 1.4 (i think) and I wanted my project to match the new format. Managed to get that working with medium-low pain level

yjkogan's avatar yjkogan (2013-04-05 02:00:43 -0600) edit
add a comment see more comments