mirror of
https://github.com/django/django.git
synced 2025-10-29 08:36:09 +00:00
Fixed #3511 -- Changed QuerySet.get() to return a MultipleObjectsReturned exception, rather than an assertion error. Thanks, Gary Wilson and cheeming.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6838 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -261,7 +261,8 @@ class _QuerySet(object):
|
||||
obj_list = list(clone)
|
||||
if len(obj_list) < 1:
|
||||
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)
|
||||
elif len(obj_list) > 1:
|
||||
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)
|
||||
return obj_list[0]
|
||||
|
||||
def create(self, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user