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: Tim Graham <timograham@…>
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 Bjorn Kristinsson, 7 years ago

Owner: changed from nobody to Bjorn Kristinsson
Status: newassigned

comment:2 by Bjorn Kristinsson, 7 years ago

Owner: Bjorn Kristinsson removed
Status: assignednew

Created a pull request, https://github.com/django/django/pull/9255, not entirely sure why the tests are failing.

comment:3 by Bjorn Kristinsson, 7 years ago

Type: BugCleanup/optimization

comment:4 by Bjorn Kristinsson, 7 years ago

Owner: set to Bjorn Kristinsson
Status: newassigned

comment:5 by Bjorn Kristinsson, 7 years ago

Cc: Bjorn Kristinsson added
Owner: Bjorn Kristinsson removed
Status: assignednew

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 Herbert Fortes, 7 years ago

Cc: Herbert Fortes 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 Tomer Chachamu, 7 years ago

Owner: set to Tomer Chachamu
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:8 by Tomer Chachamu, 7 years ago

Owner: Tomer Chachamu removed
Patch needs improvement: set
Status: assignednew

comment:9 by Bjorn Kristinsson, 7 years ago

Patch needs improvement: unset

comment:10 by Tomer Chachamu, 7 years ago

Triage Stage: AcceptedReady for checkin

comment:11 by Tim Graham, 7 years ago

Summary: Better exception message when get_queryset returns NoneAdd a helpful exception message when ListView.get_queryset() returns None

comment:12 by Tim Graham <timograham@…>, 7 years ago

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In ac6a4eb:

Fixed #28719 -- Added a helpful exception if MultipleObjectTemplateResponseMixin doesn't generate any template names.

Note: See TracTickets for help on using tickets.
Back to Top