Permalink
Browse files

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
  • Loading branch information...
1 parent 3b45a40 commit ddc156bca2519dfb60974f49d085826d0a778f77 @gdub gdub committed Aug 15, 2008
Showing with 11 additions and 1 deletion.
  1. +4 −1 django/db/models/query.py
  2. +7 −0 tests/modeltests/get_or_create/models.py
View
5 django/db/models/query.py
@@ -332,7 +332,10 @@ def get_or_create(self, **kwargs):
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):
"""
View
7 tests/modeltests/get_or_create/models.py
@@ -50,4 +50,11 @@ def __unicode__(self):
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:...
"""}

0 comments on commit ddc156b

Please sign in to comment.