From 423b3afce431fd0a1d683bca9b2b80a1c4e3c8ca Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Wed, 9 Dec 2015 14:18:44 +0200 Subject: [PATCH] Fixed #25939 -- Removed redundant transaction in QuerySet.update_or_create(). There is no need to wrap the save() call in transaction.atomic() as it's already done down the call stack in Model.save_base(). --- django/db/models/query.py | 4 +--- docs/releases/1.10.txt | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 006feb6427..e8d9006b48 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -484,9 +484,7 @@ class QuerySet(object): return obj, created for k, v in six.iteritems(defaults): setattr(obj, k, v) - - with transaction.atomic(using=self.db, savepoint=False): - obj.save(using=self.db) + obj.save(using=self.db) return obj, False def _create_object_from_params(self, lookup, params): diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 853955f936..10a517f82d 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -363,6 +363,10 @@ Miscellaneous :class:`~django.http.HttpResponse` are now closed immediately instead of when the WSGI server calls ``close()`` on the response. +* A redundant ``transaction.atomic()`` call in ``QuerySet.update_or_create()`` + is removed. This may affect query counts tested by + ``TransactionTestCase.assertNumQueries()``. + .. _deprecated-features-1.10: Features deprecated in 1.10