object save needs to be atomic transaction so entire object is saved

This commit is contained in:
Laura Klünder 2017-06-25 11:51:49 +02:00
parent 7a2854317e
commit 7c5ad70781

View file

@ -4,7 +4,7 @@ from collections import OrderedDict
from functools import reduce, wraps
from itertools import chain
from django.db import models
from django.db import models, transaction
from django.db.models import Field, FieldDoesNotExist, Manager, ManyToManyRel, Prefetch, Q
from django.utils.functional import cached_property
@ -276,6 +276,7 @@ class ModelInstanceWrapper(BaseWrapper):
author = self._author
if self.pk is None:
self._changeset.add_create(self, author=author)
with transaction.atomic():
for field, initial_value in self._initial_values.items():
if field.many_to_one:
try: