{{{#!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.
* status: new => closed
* needs_better_patch: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => New feature
Comment:
I think cloaking `ValueError` at queryset creation time would cause more
more harm than good.
Django already provides a way to sanitize/validate user input through
forms. URL patterns can also provide an extra layer of data validation.
You should make sure your lookup values have been cleaned up before using
them. The third party app [https://github.com/alex/django-filter django-
filter] does a good job at this.
--
Ticket URL: <https://code.djangoproject.com/ticket/22303#comment:1>