Opened 12 years ago

Closed 12 years ago

#18674 closed Bug (invalid)

Session app triggers an AttributeError

Reported by: loic@… Owned by: nobody
Component: contrib.sessions Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Anssi Kääriäinen)

I suspect this occurs when session has expired, or something similar and may be related to a change of API in django 1.4:

AttributeError at / 
'QuerySet' object has no attribute '_prefetch_related_lookups'

Environment:

Request Method: GET

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'xxx'
 'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "xxx/Django/django/core/handlers/base.py" in get_response
  188.                 response = middleware_method(request, response)
File "xxx/Django/django/contrib/sessions/middleware.py" in process_response
  36.                 request.session.save()
File "xxx/Django/django/contrib/sessions/backends/db.py" in save
  52.             session_data=self.encode(self._get_session(no_load=must_create)),
File "xxx/Django/django/contrib/sessions/backends/base.py" in encode
  79.         pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)
File "xxx/Django/django/db/models/query.py" in __getstate__
  65.         len(self)
File "xxx/Django/django/db/models/query.py" in __len__
  88.         if self._prefetch_related_lookups and not self._prefetch_done:

Exception Type: AttributeError at /
Exception Value: 'QuerySet' object has no attribute '_prefetch_related_lookups'

DB is MySQL.

Change History (2)

comment:1 by anonymous, 12 years ago

After some investigation, this seems to be related to sessions saved with django 1.3 ; resetting sessions app fixed the issue (at least for the moment...)

comment:2 by Anssi Kääriäinen, 12 years ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

What is likely happening here is that you have a queryset created in 1.3 stored in the session. When Django tries to load and evaluate it, the stored queryset doesn't have the prefetch stuff in it, as 1.3 didn't have it. I am not an expert of the pickle protocol, so it might be this explanation is plain wrong...

This ticket is likely invalid. But, should we advice people to clear their sessions on Django version upgrades? If the above guess is correct, similar errors (which are hard to debug) are bound to happen...

Note: See TracTickets for help on using tickets.
Back to Top