Opened 5 weeks ago

Closed 2 weeks 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: master
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 Changed 5 weeks ago by Bjorn Kristinsson

Owner: changed from nobody to Bjorn Kristinsson
Status: newassigned

comment:2 Changed 5 weeks ago by Bjorn Kristinsson

Owner: Bjorn Kristinsson deleted
Status: assignednew

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

comment:3 Changed 5 weeks ago by Bjorn Kristinsson

Type: BugCleanup/optimization

comment:4 Changed 5 weeks ago by Bjorn Kristinsson

Owner: set to Bjorn Kristinsson
Status: newassigned

comment:5 Changed 4 weeks ago by Bjorn Kristinsson

Cc: Bjorn Kristinsson added
Owner: Bjorn Kristinsson deleted
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 Changed 3 weeks ago by Herbert Fortes

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 Changed 3 weeks ago by Tomer Chachamu

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

comment:8 Changed 3 weeks ago by Tomer Chachamu

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

comment:9 Changed 3 weeks ago by Bjorn Kristinsson

Patch needs improvement: unset

comment:10 Changed 3 weeks ago by Tomer Chachamu

Triage Stage: AcceptedReady for checkin

comment:11 Changed 2 weeks ago by Tim Graham

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

comment:12 Changed 2 weeks ago by Tim Graham <timograham@…>

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