Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 'SessionStore' object has no attribute '_session_cache'

I am currently getting spammed by the error:

dictionary update sequence element #0 has length 14; 2 is required that seems to be provoked by ('SessionStore' object has no attribute '_session_cache')

I read in this question: Django project looking for "attribute '_session_cache'" that the issue might be that I don't have the django_session table, but I do and it's filled with content.

Any idea what could provoke that?

I am on Python 3.6.7, django 2.1.7

Here is the full error stack:

File "/path/to/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in _get_session
  190.             return self._session_cache

During handling of the above exception ('SessionStore' object has no attribute '_session_cache'), another exception occurred:

File "/path/to/venv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/path/to/venv/lib/python3.6/site-packages/django/utils/deprecation.py" in __call__
  90.             response = self.process_request(request)

File "/path/to/venv/lib/python3.6/site-packages/django/middleware/locale.py" in process_request
  21.         language = translation.get_language_from_request(request, check_path=i18n_patterns_used)

File "/path/to/venv/lib/python3.6/site-packages/django/utils/translation/__init__.py" in get_language_from_request
  222.     return _trans.get_language_from_request(request, check_path)

File "/path/to/venv/lib/python3.6/site-packages/django/utils/translation/trans_real.py" in get_language_from_request
  464.         lang_code = request.session.get(LANGUAGE_SESSION_KEY)

File "/path/to/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in get
  66.         return self._session.get(key, default)

File "/path/to/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in _get_session
  195.                 self._session_cache = self.load()

File "/path/to/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in load
  43.         s = self._get_session_from_db()

File "/path/to/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in _get_session_from_db
  34.                 expire_date__gt=timezone.now()

File "/path/to/venv/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/path/to/venv/lib/python3.6/site-packages/django/db/models/query.py" in get
  390.         clone = self.filter(*args, **kwargs)

File "/path/to/venv/lib/python3.6/site-packages/django/db/models/query.py" in filter
  844.         return self._filter_or_exclude(False, *args, **kwargs)

File "/path/to/venv/lib/python3.6/site-packages/django/db/models/query.py" in _filter_or_exclude
  862.             clone.query.add_q(Q(*args, **kwargs))

File "/path/to/venv/lib/python3.6/site-packages/django/db/models/sql/query.py" in add_q
  1263.         clause, _ = self._add_q(q_object, self.used_aliases)

File "/path/to/venv/lib/python3.6/site-packages/django/db/models/sql/query.py" in _add_q
  1289.                 joinpromoter.add_votes(needed_inner)

File "/path/to/venv/lib/python3.6/site-packages/django/db/models/sql/query.py" in add_votes
  2171.         self.votes.update(votes)

File "/usr/lib/python3.6/collections/__init__.py" in update
  620.                     super(Counter, self).update(iterable) # fast path when counter is empty

Exception Type: ValueError
Exception Value: dictionary update sequence element #0 has length 14; 2 is required
like image 922
Ryan Pergent Avatar asked Feb 16 '19 10:02

Ryan Pergent


1 Answers

When trying to downgrade Django 3.1 to Django 2.2, I reached the same issue.

Issue is also being tracked here: https://code.djangoproject.com/ticket/31592

From above link:

# To fix this you need to remove sessions from cache, e.g.

from django.contrib.sessions.models import Session
Session.objects.all().delete()
like image 180
Benjamin Lg Avatar answered Oct 06 '22 20:10

Benjamin Lg