Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#7640 closed (wontfix)

django.shortcuts.get_list_or_404 unnecessarily returns a list

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

Description

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 16 years ago.

Download all attachments as: .zip

Change History (7)

by Kamu, 16 years ago

Attachment: get_list_or_404.patch added

comment:1 by Kamu, 16 years ago

Has patch: set

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

comment:2 by Alex Gaynor, 16 years ago

Triage Stage: UnreviewedDesign decision needed

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

comment:3 by Malcolm Tredinnick, 16 years ago

Resolution: wontfix
Status: newclosed

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 by Dagur Páll Ammendrup, 15 years ago

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 by Alex Gaynor, 15 years ago

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

comment:6 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

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