Opened 102 minutes ago
Last modified 80 minutes ago
#37296 assigned Cleanup/optimization
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: | Unreviewed | |
| 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.
https://github.com/django/django/pull/21818