Skip to content

Commit

Permalink
feat: fix flowstart verification on room create
Browse files Browse the repository at this point in the history
feat: add transaction atomic when starting a flow, for it not to close the room if the flow start responds a error
  • Loading branch information
helllllllder committed Oct 15, 2024
1 parent 3284c13 commit a721d09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions chats/apps/api/v1/external/rooms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def get_active_room_flow_start(contact, flow_uuid, project):
fs.is_deleted = True
fs.save()
room = fs.room
room.close([], "new_room")
close_room(str(room.pk))
if room.is_active:
room.close([], "new_room")
close_room(str(room.pk))
return None
return None

Expand Down
2 changes: 2 additions & 0 deletions chats/apps/api/v1/projects/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import transaction
from django.db.models import CharField, Value
from django.db.models.functions import Concat
from django_filters.rest_framework import DjangoFilterBackend
Expand Down Expand Up @@ -263,6 +264,7 @@ def _create_flow_start_instances(self, data, flow_start):
url_name="flows",
serializer_class=ProjectFlowStartSerializer,
)
@transaction.atomic # revert room update if the flows request fails
def start_flow(self, request, *args, **kwargs):
project = self.get_object()
serializer = ProjectFlowStartSerializer(data=request.data)
Expand Down

0 comments on commit a721d09

Please sign in to comment.