Opened 6 years ago
Closed 6 years ago
#29966 closed Cleanup/optimization (fixed)
Add test coverage for BaseHandler's "The view didn't return an HttpResponse object." error
Reported by: | ziposcar | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | HTTP handling | Version: | 2.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
FILE: django/core/handlers/base.py : 131-135
The isinstance(callback, types.FunctionType)
is seems to always equal True
even if I used CBV.
I think this is due to View.as_view()
returns a function every time. So is this if statement useless?
Change History (7)
comment:1 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 6 years ago
Component: | Core (Other) → HTTP handling |
---|---|
Summary: | Useless judgment for CBV → Add test coverage for BaseHandler's "The view didn't return an HttpResponse object." error |
Triage Stage: | Unreviewed → Accepted |
follow-up: 4 comment:3 by , 6 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | set |
It covers FBV
:
https://github.com/django/django/blob/d5f4ce9849b062cc788988f2600359dc3c2890cb/django/core/handlers/base.py#L119
But I don't know how to test the CBV
. I test some class-based view like this:
class WithoutReponse(ListView): def get(self, request): pass
But, when I call this view, the callback
type is FunctionType
and the else
block doesn't execute.
comment:4 by , 6 years ago
Replying to Hasan Ramezani:
It covers
FBV
:
https://github.com/django/django/blob/d5f4ce9849b062cc788988f2600359dc3c2890cb/django/core/handlers/base.py#L119
But I don't know how to test the
CBV
. I test some class-based view like this:
class WithoutReponse(ListView): def get(self, request): passBut, when I call this view, the
callback
type isFunctionType
and theelse
block doesn't execute.
So i have the same question of CBV. And my ticket is for useless 'if' but not the test at first.
I think the callback should be always FunctionType and that 'if' is useless.
comment:5 by , 6 years ago
To exercise that branch, you can write a view like this:
class View: def __call__(self, request): pass
and use it in the URLconf as View()
.
The error message was added in 8a939224fa5df92f38532c76901975b9e765a1e9 and modified in e1d23323b631436eaae78bb5e4676d83c97d7a6c, both without tests. 27d16a3ca4a330f5aa46015ccd7d5a9ee72873b6 added Python 3 compatibility. Some tests were added in 52e0bcbc62c4df5d488b18f6a8e2cba798ec0807 (see
null_view
) but they were lost in d334f46b7a080fd3eb720141c19b37b10704a352.Tests should be added for the "The view didn't return an HttpResponse object" error.