The request's session was deleted before the request completed. The user may have logged out in a concurrent request, for example

What actually happened: A user's session was destroyed (i.e., they logged out, or the session expired) while the same user made a request with the same session key.

Why it happened: For example, it could happen if the user had two tabs open, and logged out in one of the tabs, while a request was also made from another tab. If both happened in quick succession then one would hit this error.

Do you need to worry about it?: Not unless you see lots of events like this in the logs, in which case there is something wrong. If you found the error just once, then it's nothing to worry about.


This can also happen because you store session in a dummy cache Backend.

eg :

If You have configured "DummyCache" as your default Cache system or if you have SESSION_CACHE_ALIAS points to dummy cache, There is a chance that, these sesion data can get deleted even in between your request response cycle. That is, Your Request reached Djagno server and is actively under processing.

PROBLEM

Your settings seems to be in any of this possible configuration.

Case A:

# Possible Current Configuration 
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        'LOCATION': 'unique-snowflake',
     }
}

SESSION_ENGINE = "django.contrib.sessions.backends.cache"

Or

# Another Possible Current Configuration 
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
              "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    },
    'cache_backend_for_user_session': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        'LOCATION': 'unique-snowflake',
    }
}

SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "cache_backend_for_user_session"

SOLUTION

I hope, now you got the solution, If the Session Engine Depends On Cache, It is better not to point them to DummyCache.

You can use SESSION_ENGINE with cache with cobination of any other cache

SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"  # or comfortabley anything else
CACHES = {
    'default': {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
              "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
     }
}

(Redis is my preferred configuration; you can use django.core.cache.backends.locmem.LocMemCache or django.core.cache.backends.memcached.MemcachedCache or any other option. Or even you can change Session engine from cache to something else like these if you still want to use DummyCache:

# File Based
SESSION_ENGINE = "django.contrib.sessions.backends.file"

# Works In Combination With  Current Cache and Database, fairly persistant
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"   

# Cookie Based, Browser Clearing Will lose it. 
SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"  

This error can also occur if an user is trying to login when in 'inactive' state.

Tags:

Python

Django