Skip to content

Commit

Permalink
Made QuerySet slicing return IndexError instead of DoesNotExist (and …
Browse files Browse the repository at this point in the history
…related changes).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2859 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
spookylukey committed May 6, 2006
1 parent 0727df9 commit 7a62bac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion django/db/models/base.py
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions django/db/models/query.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion django/views/defaults.py
Expand Up @@ -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
Expand Down

0 comments on commit 7a62bac

Please sign in to comment.