{"record":{"id":"c456c7f9173788ea","repo":"django/django","slug":"not-all-temporary-messages-could-be-stored","errorCode":null,"errorMessage":"Not all temporary messages could be stored.","messagePattern":"Not all temporary messages could be stored\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"django/contrib/messages/middleware.py","lineNumber":25,"sourceCode":"    \"\"\"\n    Middleware that handles temporary messages.\n    \"\"\"\n\n    def process_request(self, request):\n        request._messages = default_storage(request)\n\n    def process_response(self, request, response):\n        \"\"\"\n        Update the storage backend (i.e., save the messages).\n\n        Raise ValueError if not all messages could be stored and DEBUG is True.\n        \"\"\"\n        # A higher middleware layer may return a request which does not contain\n        # messages storage, so make no assumption that it will be there.\n        if hasattr(request, \"_messages\"):\n            unstored_messages = request._messages.update(response)\n            if unstored_messages and settings.DEBUG:\n                raise ValueError(\"Not all temporary messages could be stored.\")\n        return response\n","sourceCodeStart":7,"sourceCodeEnd":27,"githubUrl":"https://github.com/django/django/blob/b5388a3a80cafcce2e34196d8e81cf5b48eb33bb/django/contrib/messages/middleware.py#L7-L27","documentation":"ValueError raised by MessageMiddleware.process_response when, after storage.update(response), some messages remain unstored AND settings.DEBUG is True. The storage backend returns the list of messages it could not persist (e.g. cookie overflow); in debug mode Django surfaces this loudly instead of silently dropping them (middleware.py:22-25).","triggerScenarios":"Using cookie-based message storage (the default) and adding a message whose serialized form exceeds the browser cookie size limit (commonly 4093 bytes), e.g. dumping a large object into a success message. In DEBUG=True the unstored list is non-empty and line 25 raises.","commonSituations":"Storing large debug dumps or long tracebacks as messages with cookie storage; many messages accumulated across redirects; misconfigured MESSAGE_STORAGE staying at the default cookie backend while DEBUG is on.","solutions":["Switch storage to session-backed: `MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'` (requires SessionMiddleware).","Reduce message size — surface a short message and persist detail elsewhere (DB, log).","Set DEBUG=False in production so unstorable messages are silently dropped (only a stopgap; root cause is oversized data)."],"exampleFix":"// before\n# settings.py (default cookie storage, DEBUG=True)\nmessages.success(request, very_long_html_blob)\n// after\nMESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'\nmessages.success(request, 'Import finished; see report for details.')","handlingStrategy":"fallback","validationCode":"from django.conf import settings\ndef storage_is_cookie() -> bool:\n    return getattr(settings, 'MESSAGE_STORAGE', '').endswith('CookieStorage')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use session-backed storage for non-trivial message payloads.","Keep messages short; persist detail in DB or log.","Monitor unstored_messages in production logging of MessageMiddleware."],"tags":["django-messages","cookie-storage","middleware","debug-mode"],"backgroundTag":null,"analyzedSha":"b5388a3a80cafcce2e34196d8e81cf5b48eb33bb","analyzedAt":"2026-08-10T17:37:52.993Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}