Fixed #33426 -- Fixed ResolverMatch.__repr_() for class-based views.

Regression in 7c08f26bf0.
This commit is contained in:
Keryn Knight 2022-01-10 13:01:35 +00:00 committed by Mariusz Felisiak
parent 178109c173
commit f4b06a3cc1
3 changed files with 14 additions and 0 deletions

View File

@ -46,6 +46,8 @@ class ResolverMatch:
self.namespaces = [x for x in namespaces if x] if namespaces else []
self.namespace = ':'.join(self.namespaces)
if hasattr(func, 'view_class'):
func = func.view_class
if not hasattr(func, '__name__'):
# A class-based view
self._func_path = func.__class__.__module__ + '.' + func.__class__.__name__

View File

@ -17,3 +17,6 @@ Bugfixes
* Fixed a regression in Django 4.0 that caused displaying an incorrect name for
class-based views on the technical 404 debug page (:ticket:`33425`).
* Fixed a regression in Django 4.0 that caused an incorrect ``repr`` of
``ResolverMatch`` for class-based views (:ticket:`33426`).

View File

@ -1148,6 +1148,15 @@ class ResolverMatchTests(SimpleTestCase):
"namespaces=[], route='^no_kwargs/([0-9]+)/([0-9]+)/$')",
)
@override_settings(ROOT_URLCONF='urlpatterns_reverse.reverse_lazy_urls')
def test_classbased_repr(self):
self.assertEqual(
repr(resolve('/redirect/')),
"ResolverMatch(func=urlpatterns_reverse.views.LazyRedirectView, "
"args=(), kwargs={}, url_name=None, app_names=[], "
"namespaces=[], route='redirect/')",
)
@override_settings(ROOT_URLCONF='urlpatterns_reverse.urls')
def test_repr_functools_partial(self):
tests = [