Skip to content

Commit 0e91107

Browse files
committed
[fix] Add transaction on commit
1 parent f0f5305 commit 0e91107

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

openwisp_controller/geo/apps.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import swapper
55
from asgiref.sync import async_to_sync
66
from django.conf import settings
7+
from django.db import transaction
78
from django.db.models import Case, Count, Sum, When
89
from django.db.models.signals import post_save
910
from django.utils.translation import gettext_lazy as _
@@ -131,26 +132,27 @@ def _load_receivers(self):
131132
def _location_post_save_websocket_receiver(
132133
self, sender, instance, created, **kwargs
133134
):
134-
"""
135-
Sends location updates over websockets to organization specific channel group.
136-
"""
137135
if created or not instance.geometry:
138136
return
139-
channel_layer = channels.layers.get_channel_layer()
140-
async_to_sync(channel_layer.group_send)(
141-
f"loci.mobile-location.organization.{instance.organization_id}",
142-
{
143-
"type": "send_message",
144-
"message": {
145-
"id": str(instance.pk),
146-
"geometry": json.loads(instance.geometry.geojson),
147-
"address": instance.address,
148-
"name": instance.name,
149-
"type": instance.type,
150-
"is_mobile": instance.is_mobile,
137+
138+
def _send():
139+
channel_layer = channels.layers.get_channel_layer()
140+
async_to_sync(channel_layer.group_send)(
141+
f"loci.mobile-location.organization.{instance.organization_id}",
142+
{
143+
"type": "send_message",
144+
"message": {
145+
"id": str(instance.pk),
146+
"geometry": json.loads(instance.geometry.geojson),
147+
"address": instance.address,
148+
"name": instance.name,
149+
"type": instance.type,
150+
"is_mobile": instance.is_mobile,
151+
},
151152
},
152-
},
153-
)
153+
)
154+
155+
transaction.on_commit(_send)
154156

155157

156158
del LociConfig

0 commit comments

Comments
 (0)