Skip to content

Commit 6ef84ae

Browse files
committed
Using transaction hooks to emit to taiga-events only after database commit
1 parent 147ebbd commit 6ef84ae

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

taiga/events/signal_handlers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
from django.db.models import signals
18+
from django.db import connection
19+
1820
from django.dispatch import receiver
1921

2022
from taiga.base.utils.db import get_typename_for_model_instance
@@ -33,10 +35,12 @@ def on_save_any_model(sender, instance, created, **kwargs):
3335

3436
sesionid = mw.get_current_session_id()
3537

38+
type = "change"
3639
if created:
37-
events.emit_event_for_model(instance, sessionid=sesionid, type="create")
38-
else:
39-
events.emit_event_for_model(instance, sessionid=sesionid, type="change")
40+
type = "created"
41+
42+
emit_event = lambda: events.emit_event_for_model(instance, sessionid=sesionid, type=type)
43+
connection.on_commit(emit_event)
4044

4145

4246
def on_delete_any_model(sender, instance, **kwargs):
@@ -48,4 +52,5 @@ def on_delete_any_model(sender, instance, **kwargs):
4852
return
4953

5054
sesionid = mw.get_current_session_id()
51-
events.emit_event_for_model(instance, sessionid=sesionid, type="delete")
55+
emit_event = lambda: events.emit_event_for_model(instance, sessionid=sesionid, type="delete")
56+
connection.on_commit(emit_event)

0 commit comments

Comments
 (0)