#22303: Have get_object_or_404 check catch ValueError
-------------------------------+--------------------
Reporter: eddie@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
A pretty simple change, but one that I would find very helpful in
production use. Basically, get_object_or_404 catches
queryset.model.DoesNotExist and turns that into Http404, and I think it
would be helpful if it also caught ValueError to handle the case where the
passed in parameter is not valid for the field (like if it's a string and
the field type is Integer, for example).
{{{#!python
from django.shortcuts import get_object_or_404
from django.db.models.base import ModelBase
from django.contrib.contenttypes.models import ContentType
def test_get_object_or_404():
# print "<ContentType: content type>"
print get_object_or_404(ContentType, id='1')
# raise Http404: No ContentType matches the given query.
print get_object_or_404(ContentType, id='123456789')
# raise ValueError: invalid literal for int() with base 10: '123a'
print get_object_or_404(ContentType(), id='123a')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22303>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.62fa079fb921b285a1846a35050e8631%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.