Fixed #6970 -- Raise the original `IntegrityError` when all required fields aren't specified in `get_or_create` instead of a misleading `DoesNotExist` error, thanks deadwisdom.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8398 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2008-08-15 23:29:55 +00:00
parent 3b45a40c54
commit ddc156bca2
2 changed files with 11 additions and 1 deletions

View File

@ -332,7 +332,10 @@ class QuerySet(object):
return obj, True return obj, True
except IntegrityError, e: except IntegrityError, e:
transaction.savepoint_rollback(sid) transaction.savepoint_rollback(sid)
try:
return self.get(**kwargs), False return self.get(**kwargs), False
except self.model.DoesNotExist:
raise e
def latest(self, field_name=None): def latest(self, field_name=None):
""" """

View File

@ -50,4 +50,11 @@ True
False False
>>> Person.objects.count() >>> Person.objects.count()
2 2
# If you don't specify a value or default value for all required fields, you
# will get an error.
>>> p, created = Person.objects.get_or_create(first_name='Tom', last_name='Smith')
Traceback (most recent call last):
...
IntegrityError:...
"""} """}