#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)
Change History (7)
by , 16 years ago
Attachment: | get_list_or_404.patch added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|
comment:2 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
I'm going to mark this as DDN for precisely the reason you mentioned.
comment:3 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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 by , 16 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 , 16 years ago
Dagur, submit a seperate ticket for the docs patch, this ticket has already been marked as wontfix(correctly so).
p.s. I understand the method name is get_list, but it seems silly to accept a queryset and return a list.