From 0b73811e26e3c06e6ce8c2f1df7d1c97673dd08a Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Sat, 6 May 2006 12:15:19 +0000 Subject: [PATCH] Fixed QuerySet __getitem__ corner case so that it throws exceptions consistently git-svn-id: http://code.djangoproject.com/svn/django/trunk@2856 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/query.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 36d7d405bf..4173939693 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -130,7 +130,10 @@ class QuerySet(object): else: return self._clone(_offset=k, _limit=1).get() else: - return self._result_cache[k] + try: + return self._result_cache[k] + except IndexError: + raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name def __and__(self, other): combined = self._combine(other) @@ -189,7 +192,7 @@ class QuerySet(object): clone._order_by = () obj_list = list(clone) if len(obj_list) < 1: - raise self.model.DoesNotExist, "%s does not exist for %s" % (self.model._meta.object_name, kwargs) + raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name assert len(obj_list) == 1, "get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, len(obj_list), kwargs) return obj_list[0]