1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

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:
Jonathan Davis 2021-07-29 06:04:56 +01:00 committed by GitHub
parent 85d47a58bf
commit 4c6a6d5ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -478,6 +478,7 @@ answer newbie questions, and generally made Django that much better:
Jökull Sólberg Auðunsson <jokullsolberg@gmail.com> Jökull Sólberg Auðunsson <jokullsolberg@gmail.com>
Jon Dufresne <jon.dufresne@gmail.com> Jon Dufresne <jon.dufresne@gmail.com>
Jonas Haag <jonas@lophus.org> Jonas Haag <jonas@lophus.org>
Jonathan Davis <jonathandavis47780@gmail.com>
Jonatas C. D. <jonatas.cd@gmail.com> Jonatas C. D. <jonatas.cd@gmail.com>
Jonathan Buchanan <jonathan.buchanan@gmail.com> Jonathan Buchanan <jonathan.buchanan@gmail.com>
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/> Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>

View File

@ -10,6 +10,7 @@ import inspect
import re import re
import string import string
from importlib import import_module from importlib import import_module
from pickle import PicklingError
from urllib.parse import quote from urllib.parse import quote
from asgiref.local import Local 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): def get_resolver(urlconf=None):
if urlconf is None: if urlconf is None:

View File

@ -1,6 +1,7 @@
""" """
Unit tests for reverse URL lookups. Unit tests for reverse URL lookups.
""" """
import pickle
import sys import sys
import threading import threading
@ -1167,6 +1168,12 @@ class ResolverMatchTests(SimpleTestCase):
f"route='{name}/')", 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') @override_settings(ROOT_URLCONF='urlpatterns_reverse.erroneous_urls')
class ErroneousViewTests(SimpleTestCase): class ErroneousViewTests(SimpleTestCase):