Fixed #33351 -- Made path()/re_path() raise TypeError when kwargs argument is not a dict.
This commit is contained in:
parent
7e4a9a9f69
commit
75485d16a2
|
@ -57,6 +57,10 @@ def include(arg, namespace=None):
|
|||
def _path(route, view, kwargs=None, name=None, Pattern=None):
|
||||
from django.views import View
|
||||
|
||||
if kwargs is not None and not isinstance(kwargs, dict):
|
||||
raise TypeError(
|
||||
f'kwargs argument must be a dict, but got {kwargs.__class__.__name__}.'
|
||||
)
|
||||
if isinstance(view, (list, tuple)):
|
||||
# For include(...) processing.
|
||||
pattern = Pattern(route, is_endpoint=False)
|
||||
|
|
|
@ -4,7 +4,9 @@ import uuid
|
|||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import NoReverseMatch, Resolver404, path, resolve, reverse
|
||||
from django.urls import (
|
||||
NoReverseMatch, Resolver404, path, re_path, resolve, reverse,
|
||||
)
|
||||
from django.views import View
|
||||
|
||||
from .converters import DynamicConverter
|
||||
|
@ -137,6 +139,13 @@ class SimplifiedURLTests(SimpleTestCase):
|
|||
url = reverse('inner-extra', kwargs={'extra': 'something'})
|
||||
self.assertEqual(url, '/included_urls/extra/something/')
|
||||
|
||||
def test_invalid_kwargs(self):
|
||||
msg = 'kwargs argument must be a dict, but got str.'
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
path('hello/', empty_view, 'name')
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
re_path('^hello/$', empty_view, 'name')
|
||||
|
||||
def test_invalid_converter(self):
|
||||
msg = "URL route 'foo/<nonexistent:var>/' uses invalid converter 'nonexistent'."
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
|
|
Loading…
Reference in New Issue