Skip to content

Commit

Permalink
Fixed #33426 -- Fixed ResolverMatch.__repr_() for class-based views.
Browse files Browse the repository at this point in the history
Regression in 7c08f26.
  • Loading branch information
kezabelle authored and felixxm committed Jan 10, 2022
1 parent 178109c commit f4b06a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/urls/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(self, func, args, kwargs, url_name=None, app_names=None, namespaces
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__
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/4.0.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
9 changes: 9 additions & 0 deletions tests/urlpatterns_reverse/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,15 @@ def test_repr(self):
"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 = [
Expand Down

0 comments on commit f4b06a3

Please sign in to comment.