Opened 7 years ago
Closed 7 years ago
#28719 closed Cleanup/optimization (fixed)
Add a helpful exception message when ListView.get_queryset() returns None
Reported by: | Bjorn Kristinsson | Owned by: | |
---|---|---|---|
Component: | Generic views | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Bjorn Kristinsson, Herbert Fortes | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
One of my ListViews
suddenly started raising TemplateDoesNotExist
with a rather cryptic (to me) message:
Template-loader postmortem Django tried loading these templates, in this order: Using engine : This engine did not provide a list of tried templates.
It took me a while to realise this was because my get_queryset wasn't returning anything. It did some filtering based on user settings, and I didn't have a fallback for when none of the filtering steps applied.
Thought it might be helpful to have a better message is no template names are found and object_list
is None
. Suggesting: "Expected a queryset, but found None. Please check that <cls>.get_queryset() returns a queryset." Pull request coming up.
Change History (12)
comment:1 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 7 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:3 by , 7 years ago
Type: | Bug → Cleanup/optimization |
---|
comment:4 by , 7 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:5 by , 7 years ago
Cc: | added |
---|---|
Owner: | removed |
Status: | assigned → new |
Oki, guess someone else than me needs to move this forward. The PR is passing tests now, comments addressed - but someone else needs to accept or reject it.
comment:6 by , 7 years ago
Cc: | added |
---|
Hi,
I read the patch and ran the tests.
Ran 202 tests in 3.730s
OK
It seems that the patch does what the author wants. If
there is no information at all raise 'ImproperlyConfigured'.
patch ok
tests ok
docs ok
I am not changing to 'Ready for checkin' because this is
my first time doing a review.
Regards,
Herbert
comment:7 by , 7 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:8 by , 7 years ago
Owner: | removed |
---|---|
Patch needs improvement: | set |
Status: | assigned → new |
comment:9 by , 7 years ago
Patch needs improvement: | unset |
---|
comment:10 by , 7 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:11 by , 7 years ago
Summary: | Better exception message when get_queryset returns None → Add a helpful exception message when ListView.get_queryset() returns None |
---|
Created a pull request, https://github.com/django/django/pull/9255, not entirely sure why the tests are failing.