Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7640 closed (wontfix)

django.shortcuts.get_list_or_404 unnecessarily returns a list

Reported by: Kamu Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


django.shortcuts.get_list_or_404 returns a list, which prohibits queryset chaining etc. e.g.

stats = get_list_or_404(CityStats, country=countryid, snapshot=period).order_by('city__name')

is not possible due to the returning of a list. It is much better to return the queryset it makes in the first place!

(sorry if the patch is incorrectly formatted, as I am using git-svn and I am new to it, as well as diff/patches :))

Attachments (1)

get_list_or_404.patch (614 bytes) - added by Kamu 8 years ago.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by Kamu

comment:1 Changed 8 years ago by Kamu

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

p.s. I understand the method name is get_list, but it seems silly to accept a queryset and return a list.

comment:2 Changed 8 years ago by Alex

  • Triage Stage changed from Unreviewed to Design decision needed

I'm going to mark this as DDN for precisely the reason you mentioned.

comment:3 Changed 8 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from new to closed

Yes, the name tells you it will return a list. For it not to do so would mean the name was wrong.

It's a shortcut method for one simple case. You don't need it, so if you want something that returns a queryset, just do that and test for emptiness later.

comment:4 Changed 7 years ago by Dagur

The documentation needs to be fixed. get_list_or_404 is not equivalent to doing:

def my_view(request):

my_objects = MyModel.objects.filter(published=True)
if not my_objects:

raise Http404

because that would indeed return a queryset.

comment:5 Changed 7 years ago by Alex

Dagur, submit a seperate ticket for the docs patch, this ticket has already been marked as wontfix(correctly so).

comment:6 Changed 5 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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