-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #32260 handler500 as a Class-based view raises SystemCheckError #13766
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add tests for CBV handlers as well
django/urls/resolvers.py
Outdated
if signature.parameters.get('self'): | ||
args = [None] * 2 # Class based views always take two arguements, (self, request). | ||
else: | ||
args = [None] * num_parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to allow an extra parameter when it's a class based view
In other words
# Class based views always take two arguements, (self, request).
Is not not true
if signature.parameters.get('self'): | |
args = [None] * 2 # Class based views always take two arguements, (self, request). | |
else: | |
args = [None] * num_parameters | |
if signature.parameters.get('self'): | |
num_parameters += 1 | |
args = [None] * num_parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your suggestion!
Simply added +1 to the num_parameters will make the value of num_parameters for handler404, handler403 and handler400 as 3 which is not correct.
django/django/urls/resolvers.py
Line 421 in 8d7085e
for status_code, num_parameters in [(400, 2), (403, 2), (404, 2), (500, 1)]: |
I can change it as if signature.parameters.get('self') and status_code==500:
but that would be the greatest solution in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add tests for CBV handlers as well
Yes I will do that right away!
c8daee1
to
4411908
Compare
_check_custom_error_handlers in django/urls/resolver.py now checks if the handler is a function based view or class based view. For class based view, num_parameters needs to be 2 as class based views take two parameters (self, request). Added tests for class based views too.
4411908
to
b91a40e
Compare
I think this ticket is going in the wrong direction and the check has really exposed a bug in the return value of
I think we should fix |
That does make a lot of sense. Self should not be present on the signature in the first place! |
@abbasidaniyal Thanks, feel-free to send a new PR. |
@felixxm Yes. I'm extremely sorry for delaying this. I'll be sending a new PR soon! |
_check_custom_error_handlers in django/urls/resolver.py now checks if the handler is a function based view or class based view.
For class based view, num_parameters needs to be 2 as class based views take two parameters (self, request).