Opened 6 years ago

Closed 6 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'


Request Method: GET

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
Installed Middleware:

File "xxx/Django/django/core/handlers/" in get_response
  188.                 response = middleware_method(request, response)
File "xxx/Django/django/contrib/sessions/" in process_response
File "xxx/Django/django/contrib/sessions/backends/" in save
  52.             session_data=self.encode(self._get_session(no_load=must_create)),
File "xxx/Django/django/contrib/sessions/backends/" in encode
  79.         pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)
File "xxx/Django/django/db/models/" in __getstate__
  65.         len(self)
File "xxx/Django/django/db/models/" 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 Changed 6 years ago by anonymous

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 Changed 6 years ago by Anssi Kääriäinen

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