{{{
def get_list_or_404(klass, *args, **kwargs):
queryset = _get_queryset(klass)
try:
obj_list = list(queryset.filter(*args, **kwargs))
except AttributeError:
klass__name = klass.__name__ if isinstance(klass, type) else
klass.__class__.__name__
raise ValueError(
"First argument to get_list_or_404() must be a Model, Manager,
or "
"QuerySet, not '%s'." % klass__name
)
if not obj_list:
raise Http404('No %s matches the given query.' %
queryset.model._meta.object_name)
return obj_list
}}}
The try-catch block is far too broad. Any `AttributeError` raised during
the call to `filter` is swallowed and converted into an incorrect and
confusing error message. This should be changed to either `if not
hasattr(queryset, 'filter'): raise ...` or `try: method = queryset.filter;
except AttributeError: ...`. The same thing happens with
`queryset.get(*args, **kwargs)` in `get_object_or_404`'.
--
Ticket URL: <https://code.djangoproject.com/ticket/29135>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
* component: Uncategorized => Core (Other)
--
Ticket URL: <https://code.djangoproject.com/ticket/29135#comment:1>
* owner: nobody => Yuri Shikanov
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29135#comment:2>
Comment (by Yuri Shikanov):
I've opened [https://github.com/django/django/pull/9705 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29135#comment:3>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29135#comment:4>
* needs_better_patch: 0 => 1
Comment:
Just minor edits on patch needed. (Comments on PR.)
--
Ticket URL: <https://code.djangoproject.com/ticket/29135#comment:5>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29135#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"eb002e7892793fb9f593efaed8d3ea52a2bfc96c" eb002e78]:
{{{
#!CommitTicketReference repository=""
revision="eb002e7892793fb9f593efaed8d3ea52a2bfc96c"
Fixed #29135 -- Prevented get_object/list_or_404() from hiding
AttributeError raised by QuerySet filtering.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29135#comment:7>