Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed QuerySet __getitem__ corner case so that it throws exceptions c…

…onsistently

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2856 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0b73811e26e3c06e6ce8c2f1df7d1c97673dd08a 1 parent 862328a
@spookylukey spookylukey authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 django/db/models/query.py
View
7 django/db/models/query.py
@@ -130,7 +130,10 @@ def __getitem__(self, k):
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 @@ def get(self, *args, **kwargs):
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]
Please sign in to comment.
Something went wrong with that request. Please try again.