Hi,

I upgraded from Django 1.7.x to 1.9.5 and now get sporadic errors like this 
that come from the django.contrib.sessions module (the full stack trace is 
below):

Exception Type: ValueError at /subscriptions/
Exception Value: make_aware expects a naive datetime, got 2016-04-21 
23:26:19.247888+00:00

Sporadic in the sense that when I visit the site and get the error, I can 
refresh and it is gone. If I wait for a while (e.g. the next day) and go to 
the site again, the error is back once and then goes away again if I 
refresh. I haven't figured out the timespan I need to wait before the error 
reappears yet, but assume it has to do with caching.

I think it cannot be a problem with my own code, as the stack trace only 
contains stock Django functionality and my own code doesn't directly access 
or meddle with the Session models. If I understand correctly, Session 
objects are selected from the database with a filter on their expire_date, 
and at some point, this expire_date datetime object should be converted 
from native to aware, which fails because it is aware already.

My first assumption was that there was a change from Django 1.7 to 1.9 and 
that the objects already saved in the database with Django 1.7 code are no 
longer compatible with Django 1.9. So I deleted all Session objects from 
the database and then start a new session by logging in again. However, the 
resulting Session object also has an expire_date which is aware already, so 
it would run into the same problem again.

I use sqlite as the database backend, if that's relevant.

Any idea what the problem might be?

Thanks in advance!
Jens

--

ValueError at /subscriptions/
make_aware expects a naive datetime, got 2016-04-21 23:26:19.247888+00:00

Request Method: GET
Request URL: https://.../subscriptions/ 
Django Version: 1.9.5
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path: ['/root/.virtualenvs/django19/lib/python2.7/site-packages', 
'/var/www/MYAPP', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', 
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7']
Server time: Fri, 15 Apr 2016 21:02:49 +0200
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'MYAPP',
'django_extensions',
'debug_toolbar')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:  

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/core/handlers/base.py"
 
in get_response
 149.                     response = 
self.process_exception_by_middleware(e, request)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/core/handlers/base.py"
 
in get_response
 147.                     response = wrapped_callback(request, 
*callback_args, **callback_kwargs)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/auth/decorators.py"
 
in _wrapped_view
 22.             if test_func(request.user):

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/auth/decorators.py"
 
in <lambda>
 46.         lambda u: u.is_authenticated(),

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/utils/functional.py"
 
in inner
 204.             self._setup()

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/utils/functional.py"
 
in _setup
 351.         self._wrapped = self._setupfunc()

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/auth/middleware.py"
 
in <lambda>
 22.         request.user = SimpleLazyObject(lambda: get_user(request))

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/auth/middleware.py"
 
in get_user
 10.         request._cached_user = auth.get_user(request)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/auth/__init__.py"
 
in get_user
 167.         user_id = _get_user_session_key(request)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/auth/__init__.py"
 
in _get_user_session_key
 59.     return 
get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py"
 
in __getitem__
 48.         return self._session[key]

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py"
 
in _get_session
 198.                 self._session_cache = self.load()

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py"
 
in load
 33.                 expire_date__gt=timezone.now()

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/models/manager.py"
 
in manager_method
 122.                 return getattr(self.get_queryset(), name)(*args, 
**kwargs)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/models/query.py"
 
in get
 381.         num = len(clone)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/models/query.py"
 
in __len__
 240.         self._fetch_all()

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/models/query.py"
 
in _fetch_all
 1074.             self._result_cache = list(self.iterator())

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/models/query.py"
 
in __iter__
 68.         for row in compiler.results_iter(results):

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/models/sql/compiler.py"
 
in results_iter
 808.                     row = self.apply_converters(row, converters)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/models/sql/compiler.py"
 
in apply_converters
 792.                 value = converter(value, expression, self.connection, 
self.query.context)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/db/backends/sqlite3/operations.py"
 
in convert_datetimefield_value
 216.                 value = timezone.make_aware(value, 
self.connection.timezone)

File 
"/root/.virtualenvs/django19/lib/python2.7/site-packages/django/utils/timezone.py"
 
in make_aware
 369.                 "make_aware expects a naive datetime, got %s" % value)

Exception Type: ValueError at /subscriptions/
Exception Value: make_aware expects a naive datetime, got 2016-04-21 
23:26:19.247888+00:00

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3b385124-3df2-4f89-bce7-65d10e61bf93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to