Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made QuerySet slicing return IndexError instead of DoesNotExist (and …

…related changes).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2859 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7a62bac56ea484adb21f49ee88a322d1e08f74ba 1 parent 0727df9
@spookylukey spookylukey authored
View
5 django/db/models/base.py
@@ -264,7 +264,10 @@ def _get_next_or_previous_by_FIELD(self, field, is_next):
q = self.__class__._default_manager.order_by((not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name)
q._where.append(where)
q._params.extend([param, param, getattr(self, self._meta.pk.attname)])
- return q[0]
+ try:
+ return q[0]
+ except IndexError, e:
+ raise self.DoesNotExist, e.args
def _get_next_or_previous_in_order(self, is_next):
cachename = "__%s_order_cache" % is_next
View
10 django/db/models/query.py
@@ -128,12 +128,12 @@ def __getitem__(self, k):
else:
return list(self._clone(_offset=offset, _limit=limit))[::k.step]
else:
- return self._clone(_offset=k, _limit=1).get()
+ try:
+ return self._clone(_offset=k, _limit=1).get()
+ except self.model.DoesNotExist, e:
+ raise IndexError, e.args
else:
- try:
- return self._result_cache[k]
- except IndexError:
- raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name
+ return self._result_cache[k]
def __and__(self, other):
combined = self._combine(other)
View
2  django/views/defaults.py
@@ -35,7 +35,7 @@ def shortcut(request, content_type_id, object_id):
if field.rel.to is Site:
try:
object_domain = getattr(obj, field.name).all()[0].domain
- except Site.DoesNotExist:
+ except IndexError:
pass
if object_domain is not None:
break
Please sign in to comment.
Something went wrong with that request. Please try again.