From faa8c71fd9e97794e73f7e7564446846d72d8bb2 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 3 May 2014 23:34:55 +0200 Subject: [PATCH] Moved misplaced transaction.atomic from 0dce44e16b Thanks Florian Apolloner for noticing the issue and Aymeric Augustin for the expertise. Refs #22540. --- django/db/models/query.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 0a5e9073d6..9b577ada21 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -364,8 +364,7 @@ class QuerySet(object): """ obj = self.model(**kwargs) self._for_write = True - with transaction.atomic(using=self.db): - obj.save(force_insert=True, using=self.db) + obj.save(force_insert=True, using=self.db) return obj def bulk_create(self, objs, batch_size=None): @@ -448,7 +447,8 @@ class QuerySet(object): Used by get_or_create and update_or_create """ try: - obj = self.create(**params) + with transaction.atomic(using=self.db): + obj = self.create(**params) return obj, True except IntegrityError: exc_info = sys.exc_info()