diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py
index 81c436fa04..1d390c71dd 100644
--- a/django/contrib/messages/storage/cookie.py
+++ b/django/contrib/messages/storage/cookie.py
@@ -161,21 +161,8 @@ class CookieStorage(BaseStorage):
return None
try:
return self.signer.unsign_object(data, serializer=MessageSerializer)
- # RemovedInDjango41Warning: when the deprecation ends, replace with:
- #
- # except (signing.BadSignature, json.JSONDecodeError):
- # pass
- except signing.BadSignature:
- decoded = None
- except (binascii.Error, json.JSONDecodeError):
- decoded = self.signer.unsign(data)
-
- if decoded:
- # RemovedInDjango41Warning.
- try:
- return json.loads(decoded, cls=MessageDecoder)
- except json.JSONDecodeError:
- pass
+ except (signing.BadSignature, binascii.Error, json.JSONDecodeError):
+ pass
# Mark the data as used (so it gets removed) since something was wrong
# with the data.
self.used = True
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt
index 157a05acdb..9066d47ac7 100644
--- a/docs/releases/4.1.txt
+++ b/docs/releases/4.1.txt
@@ -263,3 +263,6 @@ to remove usage of these features.
* The ``django.core.cache.backends.memcached.MemcachedCache`` backend is
removed.
+
+* Support for the pre-Django 3.2 format of messages used by
+ ``django.contrib.messages.storage.cookie.CookieStorage`` is removed.
diff --git a/tests/messages_tests/test_cookie.py b/tests/messages_tests/test_cookie.py
index b622b7159b..53cf693f61 100644
--- a/tests/messages_tests/test_cookie.py
+++ b/tests/messages_tests/test_cookie.py
@@ -1,4 +1,3 @@
-import binascii
import json
import random
@@ -8,7 +7,6 @@ from django.contrib.messages.storage.base import Message
from django.contrib.messages.storage.cookie import (
CookieStorage, MessageDecoder, MessageEncoder,
)
-from django.core.signing import b64_decode, get_cookie_signer
from django.test import SimpleTestCase, override_settings
from django.utils.crypto import get_random_string
from django.utils.safestring import SafeData, mark_safe
@@ -179,18 +177,3 @@ class CookieTests(BaseTests, SimpleTestCase):
storage = self.get_storage()
self.assertIsInstance(encode_decode(mark_safe("Hello Django!")), SafeData)
self.assertNotIsInstance(encode_decode("Hello Django!"), SafeData)
-
- def test_legacy_encode_decode(self):
- # RemovedInDjango41Warning: pre-Django 3.2 encoded messages will be
- # invalid.
- storage = self.storage_class(self.get_request())
- messages = ['this', Message(0, 'Successfully signed in as admin@example.org')]
- # Encode/decode a message using the pre-Django 3.2 format.
- encoder = MessageEncoder()
- value = encoder.encode(messages)
- with self.assertRaises(binascii.Error):
- b64_decode(value.encode())
- signer = get_cookie_signer(salt=storage.key_salt)
- encoded_messages = signer.sign(value)
- decoded_messages = storage._decode(encoded_messages)
- self.assertEqual(messages, decoded_messages)