Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#29664 closed Cleanup/optimization (wontfix)

Need Proper error handling for CBV in urls.

Reported by: Amar Owned by: emiamar@…
Component: Core (URLs) Version: 2.1
Severity: Normal Keywords:
Cc: emiamar@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Amar)

When in if one misses to call as_view() (Example shown below) method django throws weird error. Need better way of handling error

Incorrect definition

urlpatterns = [
    path('hello/', HelloView)

Correct definition

urlpatterns = [
    path('hello/', HelloView.as_view())


TypeError at /hello/

__init__() takes 1 positional argument but 2 were given

Request Method: 	GET
Request URL: 	http://localhost:8000/hello/
Django Version: 	2.0.7
Exception Type: 	TypeError
Exception Value: 	

__init__() takes 1 positional argument but 2 were given

Exception Location: 	/home/amar/.virtualenvs/djmongo/lib/python3.6/site-packages/django/core/handlers/ in _get_response, line 126

This make it really hard to figure out actual error. I faced this once and had to struggle for hours to understand what went wrong. Here is my PR

Change History (3)

comment:1 Changed 4 years ago by Amar

Description: modified (diff)

comment:2 Changed 4 years ago by Ramiro Morales

I'm afraid catching TypeError around the view callable execution is a too coarse net to have. what if the view (be it either a traditional function-based view, or a correctly invoked class based view via it's .as_view() method, etc.) result in a legitimate TypeError? Wouldn't the useful traceback that cold help the developer diagnose the issue be replaced by the new one that reports "Check if as_view() method called properly"?

In the end there a line that needs to be placed between handholding a developer which face this kind of problems, and the expectation of them reading the relevant documentation, i.e.

I'm ok with trying to be more helpful but not at the expense of reducing the usefulness of normal Python debugging techniques.

Version 1, edited 4 years ago by Ramiro Morales (previous) (next) (diff)

comment:3 Changed 4 years ago by Carlton Gibson

Resolution: wontfix
Status: assignedclosed

I have to agree 100% with Ramiro.

I’m going to close this as wontfix. If a proposal comes up that catches a user programming error here without interfering with legitimate usage then we can review but I don’t think we can consider this an Open Issue’'.

Last edited 4 years ago by Carlton Gibson (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top