diff --git a/django/db/models/query.py b/django/db/models/query.py index d82cdf4d96..1bc84c47ca 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -332,7 +332,10 @@ class QuerySet(object): return obj, True except IntegrityError, e: transaction.savepoint_rollback(sid) - return self.get(**kwargs), False + try: + return self.get(**kwargs), False + except self.model.DoesNotExist: + raise e def latest(self, field_name=None): """ diff --git a/tests/modeltests/get_or_create/models.py b/tests/modeltests/get_or_create/models.py index 3a1b447c97..5c35bb4bec 100644 --- a/tests/modeltests/get_or_create/models.py +++ b/tests/modeltests/get_or_create/models.py @@ -50,4 +50,11 @@ True False >>> Person.objects.count() 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:... """}