Opened 3 years ago

Last modified 3 years ago

#32260 closed Cleanup/optimization

handler500 as a Class-based view raises SystemCheckError — at Version 1

Reported by: Daniyal Abbasi Owned by: Daniyal Abbasi
Component: Core (System checks) 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: no UI/UX: no

Description (last modified by Daniyal Abbasi)

Setting handler500 as a Class-Based view raises the following error which running checks.

$ python manage.py check
SystemCheckError: System check identified some issues:

ERRORS:
?: (urls.E007) The custom handler500 view 'path.to.my.MyView' does not take the correct number of arguments (request).

In my root urls.py, I have the following configuration,

handler404 = MyView.as_view()
handler500 = MyView.as_view()

I believe this is due to the function _check_custom_error_handlers in django/urls/resolver.py. The signature variable in this function is expected to match (request, exception) for all handlers except for handler500 which is expected to have only (request). A positional argument, template_name is also present.

While using class based views, we get two positional arguments (self, request) and then it recieves *args and * *kwargs. The check is permitting other handlers as the number of arguments coincidentally match.

I suggest a fix in the _check_custom_error_handlers which first checks if the handler* are function based or class based, and then it preceed the check with the appropriate number of arguments.

Change History (1)

comment:1 by Daniyal Abbasi, 3 years ago

Description: modified (diff)
Owner: changed from nobody to Daniyal Abbasi
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top