mirror of https://github.com/django/django.git
Fixed #23895 -- Prevented pickling of ResolverMatch.
Pickling a ResolverMatch did not work correctly in many cases, especially with CBVs and URLResolvers in the list of tried URL paths.
This commit is contained in:
parent
85d47a58bf
commit
4c6a6d5ac7
1
AUTHORS
1
AUTHORS
|
@ -478,6 +478,7 @@ answer newbie questions, and generally made Django that much better:
|
|||
Jökull Sólberg Auðunsson <jokullsolberg@gmail.com>
|
||||
Jon Dufresne <jon.dufresne@gmail.com>
|
||||
Jonas Haag <jonas@lophus.org>
|
||||
Jonathan Davis <jonathandavis47780@gmail.com>
|
||||
Jonatas C. D. <jonatas.cd@gmail.com>
|
||||
Jonathan Buchanan <jonathan.buchanan@gmail.com>
|
||||
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
|
||||
|
|
|
@ -10,6 +10,7 @@ import inspect
|
|||
import re
|
||||
import string
|
||||
from importlib import import_module
|
||||
from pickle import PicklingError
|
||||
from urllib.parse import quote
|
||||
|
||||
from asgiref.local import Local
|
||||
|
@ -71,6 +72,9 @@ class ResolverMatch:
|
|||
)
|
||||
)
|
||||
|
||||
def __reduce_ex__(self, protocol):
|
||||
raise PicklingError(f'Cannot pickle {self.__class__.__qualname__}.')
|
||||
|
||||
|
||||
def get_resolver(urlconf=None):
|
||||
if urlconf is None:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
Unit tests for reverse URL lookups.
|
||||
"""
|
||||
import pickle
|
||||
import sys
|
||||
import threading
|
||||
|
||||
|
@ -1167,6 +1168,12 @@ class ResolverMatchTests(SimpleTestCase):
|
|||
f"route='{name}/')",
|
||||
)
|
||||
|
||||
@override_settings(ROOT_URLCONF='urlpatterns.path_urls')
|
||||
def test_pickling(self):
|
||||
msg = 'Cannot pickle ResolverMatch.'
|
||||
with self.assertRaisesMessage(pickle.PicklingError, msg):
|
||||
pickle.dumps(resolve('/users/'))
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='urlpatterns_reverse.erroneous_urls')
|
||||
class ErroneousViewTests(SimpleTestCase):
|
||||
|
|
Loading…
Reference in New Issue