mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
[1.5.x] Fixed #19432 -- Provided better error message for get_object_or_404
Thanks Kit Sunde for the report and Brian Holdefehr for the initial
patch.
Backport of 6ed6a18a0 from master.
This commit is contained in:
@@ -80,3 +80,28 @@ class GetObjectOr404Tests(TestCase):
|
||||
get_list_or_404(Article.objects.all(), title__icontains="Run"),
|
||||
[article]
|
||||
)
|
||||
|
||||
def test_bad_class(self):
|
||||
# Given an argument klass that is not a Model, Manager, or Queryset
|
||||
# raises a helpful ValueError message
|
||||
self.assertRaisesMessage(ValueError,
|
||||
"Object is of type 'str', but must be a Django Model, Manager, "
|
||||
"or QuerySet",
|
||||
get_object_or_404, "Article", title__icontains="Run"
|
||||
)
|
||||
|
||||
class CustomClass(object):
|
||||
pass
|
||||
|
||||
self.assertRaisesMessage(ValueError,
|
||||
"Object is of type 'CustomClass', but must be a Django Model, "
|
||||
"Manager, or QuerySet",
|
||||
get_object_or_404, CustomClass, title__icontains="Run"
|
||||
)
|
||||
|
||||
# Works for lists too
|
||||
self.assertRaisesMessage(ValueError,
|
||||
"Object is of type 'list', but must be a Django Model, Manager, "
|
||||
"or QuerySet",
|
||||
get_list_or_404, [Article], title__icontains="Run"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user