Skip to content

Commit be9553f

Browse files
authored
Merge pull request #86 from amirmotlagh/master
move save() and delete() functions into transaction
2 parents 26fdf3b + 06f8ed9 commit be9553f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

django_lifecycle/mixins.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, List
44

55
from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist
6+
from django.db import transaction
67
from django.utils.functional import cached_property
78

89
from . import NotSet
@@ -114,6 +115,7 @@ def _clear_watched_fk_model_cache(self):
114115
if field.is_relation and field.is_cached(self):
115116
field.delete_cached_value(self)
116117

118+
@transaction.atomic
117119
def save(self, *args, **kwargs):
118120
skip_hooks = kwargs.pop("skip_hooks", False)
119121
save = super().save
@@ -141,6 +143,7 @@ def save(self, *args, **kwargs):
141143

142144
self._initial_state = self._snapshot_state()
143145

146+
@transaction.atomic
144147
def delete(self, *args, **kwargs):
145148
self._run_hooked_methods(BEFORE_DELETE)
146149
value = super().delete(*args, **kwargs)

0 commit comments

Comments
 (0)