Changeset 6838
- Timestamp:
- 12/02/07 12:21:07 (7 months ago)
- Files:
-
- django/trunk/django/core/exceptions.py (modified) (1 diff)
- django/trunk/django/db/models/base.py (modified) (2 diffs)
- django/trunk/django/db/models/query.py (modified) (1 diff)
- django/trunk/django/shortcuts/__init__.py (modified) (1 diff)
- django/trunk/docs/shortcuts.txt (modified) (1 diff)
- django/trunk/tests/modeltests/get_object_or_404/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/exceptions.py
r2809 r6838 4 4 "The requested object does not exist" 5 5 silent_variable_failure = True 6 7 class MultipleObjectsReturned(Exception): 8 "The query returned multiple objects when only one was expected." 9 pass 6 10 7 11 class SuspiciousOperation(Exception): django/trunk/django/db/models/base.py
r6732 r6838 2 2 import django.db.models.manager 3 3 from django.core import validators 4 from django.core.exceptions import ObjectDoesNotExist 4 from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned 5 5 from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist 6 6 from django.db.models.fields.related import OneToOneRel, ManyToOneRel … … 36 36 new_class.add_to_class('_meta', Options(attrs.pop('Meta', None))) 37 37 new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {})) 38 new_class.add_to_class('MultipleObjectsReturned', 39 types.ClassType('MultipleObjectsReturned', (MultipleObjectsReturned, ), {})) 38 40 39 41 # Build complete list of parents django/trunk/django/db/models/query.py
r6411 r6838 262 262 if len(obj_list) < 1: 263 263 raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name 264 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) 264 elif len(obj_list) > 1: 265 raise self.model.MultipleObjectsReturned, "get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, len(obj_list), kwargs) 265 266 return obj_list[0] 266 267 django/trunk/django/shortcuts/__init__.py
r6257 r6838 39 39 arguments and keyword arguments are used in the get() query. 40 40 41 Note: Like with get(), an AssertionErrorwill be raised if more than one41 Note: Like with get(), an MultipleObjectsReturned will be raised if more than one 42 42 object is found. 43 43 """ django/trunk/docs/shortcuts.txt
r6234 r6838 99 99 raise Http404 100 100 101 Note: As with ``get()``, an `` AssertionError`` will be raised if more than102 one object is found.101 Note: As with ``get()``, an ``MultipleObjectsReturned`` exception will be 102 raised if more than one object is found. 103 103 104 104 .. _get(): ../db-api/#get-kwargs django/trunk/tests/modeltests/get_object_or_404/models.py
r5876 r6838 79 79 Traceback (most recent call last): 80 80 ... 81 AssertionError: get() returned more than one Author -- it returned ...! Lookup parameters were {}81 MultipleObjectsReturned: get() returned more than one Author -- it returned ...! Lookup parameters were {} 82 82 83 83 # Using an EmptyQuerySet raises a Http404 error.
