Opened 3 weeks ago

Closed 2 weeks ago

#37296 closed Cleanup/optimization (fixed)

Include the received type in the path()/re_path() error message for an invalid view

Reported by: osmnvaslan Owned by: osmnvaslan
Component: Core (URLs) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

path() and re_path() raise a generic TypeError when the view argument is neither a callable, a list/tuple (as returned by include()), nor a View instance:
view must be a callable or a list/tuple in the case of include().

The message doesn't report what was actually passed, unlike the two neighboring error branches in django/urls/conf.py: the invalid kwargs branch (#33351) ends with but got {kwargs.class.name}., and the View instance branch says pass {name}.as_view(), not {name}().

A common way to reach this branch is passing a string view — the pre-1.10 url(r"", "app.views.home") style, removed in Django 2.0 — where the current message gives no hint that a str was the problem.

Proposal: append the received type, consistent with the sibling branches:
view must be a callable or a list/tuple in the case of include(), but got str.
A patch is ready, including a regression test that updates the existing test_invalid_view.

Change History (4)

comment:3 by Clifford Gama, 3 weeks ago

Triage Stage: UnreviewedReady for checkin

comment:4 by Sarah Boyce <42296566+sarahboyce@…>, 2 weeks ago

Resolution: fixed
Status: assignedclosed

In fdfbb711:

Fixed #37296 -- Included the invalid view type in path()/re_path() error.

The fallback TypeError raised by path() and re_path() for an invalid view
did not report the received type, unlike the neighboring errors for an
invalid kwargs argument or a class-based view instance.

Note: See TracTickets for help on using tickets.
Back to Top