mirror of
https://github.com/django/django.git
synced 2025-09-23 10:42:45 +00:00
Fixed #16340 -- Made get_or_create()
re-raise any IntegrityError
with its original traceback. Thanks to d0ugal and Jonas Obrist.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17333 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
fc9e0606d5
commit
31b1cbc623
2 changed files with 16 additions and 1 deletions
|
@ -4,6 +4,7 @@ The main QuerySet implementation. This provides the public API for the ORM.
|
|||
|
||||
import copy
|
||||
import itertools
|
||||
import sys
|
||||
|
||||
from django.db import connections, router, transaction, IntegrityError
|
||||
from django.db.models.fields import AutoField
|
||||
|
@ -450,10 +451,12 @@ class QuerySet(object):
|
|||
return obj, True
|
||||
except IntegrityError, e:
|
||||
transaction.savepoint_rollback(sid, using=self.db)
|
||||
exc_info = sys.exc_info()
|
||||
try:
|
||||
return self.get(**lookup), False
|
||||
except self.model.DoesNotExist:
|
||||
raise e
|
||||
# Re-raise the IntegrityError with its original traceback.
|
||||
raise exc_info[1], None, exc_info[2]
|
||||
|
||||
def latest(self, field_name=None):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue