mirror of
https://github.com/django/django.git
synced 2025-09-24 19:23:03 +00:00
Added savepoint protection to get_or_create() to avoid problems on PostgreSQL.
Fixed #7402. Also made savepoint handling easier to use when wrapped around calls that might commit a transaction. This is tested by the get_or_create tests. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8315 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
220993bcc5
commit
3eb8074808
2 changed files with 14 additions and 2 deletions
|
@ -326,9 +326,12 @@ class QuerySet(object):
|
|||
params = dict([(k, v) for k, v in kwargs.items() if '__' not in k])
|
||||
params.update(defaults)
|
||||
obj = self.model(**params)
|
||||
sid = transaction.savepoint()
|
||||
obj.save()
|
||||
transaction.savepoint_commit(sid)
|
||||
return obj, True
|
||||
except IntegrityError, e:
|
||||
transaction.savepoint_rollback(sid)
|
||||
return self.get(**kwargs), False
|
||||
|
||||
def latest(self, field_name=None):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue