From 4a2e6af9b59b4905122bee8e49aa2b1fb0279892 Mon Sep 17 00:00:00 2001 From: Alex Chim <132866042+AlexChim1231@users.noreply.github.com> Date: Thu, 14 Aug 2025 15:54:25 +0800 Subject: [PATCH] Fixes #23921 (#23924) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- api/controllers/service_api/app/conversation.py | 9 +++++---- api/services/conversation_service.py | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/controllers/service_api/app/conversation.py b/api/controllers/service_api/app/conversation.py index 79c860e6b..073307ac4 100644 --- a/api/controllers/service_api/app/conversation.py +++ b/api/controllers/service_api/app/conversation.py @@ -1,5 +1,3 @@ -import json - from flask_restful import Resource, marshal_with, reqparse from flask_restful.inputs import int_range from sqlalchemy.orm import Session @@ -136,12 +134,15 @@ class ConversationVariableDetailApi(Resource): variable_id = str(variable_id) parser = reqparse.RequestParser() - parser.add_argument("value", required=True, location="json") + # using lambda is for passing the already-typed value without modification + # if no lambda, it will be converted to string + # the string cannot be converted using json.loads + parser.add_argument("value", required=True, location="json", type=lambda x: x) args = parser.parse_args() try: return ConversationService.update_conversation_variable( - app_model, conversation_id, variable_id, end_user, json.loads(args["value"]) + app_model, conversation_id, variable_id, end_user, args["value"] ) except services.errors.conversation.ConversationNotExistsError: raise NotFound("Conversation Not Exists.") diff --git a/api/services/conversation_service.py b/api/services/conversation_service.py index 713c4c678..d76981a23 100644 --- a/api/services/conversation_service.py +++ b/api/services/conversation_service.py @@ -277,6 +277,11 @@ class ConversationService: # Validate that the new value type matches the expected variable type expected_type = SegmentType(current_variable.value_type) + + # There is showing number in web ui but int in db + if expected_type == SegmentType.INTEGER: + expected_type = SegmentType.NUMBER + if not expected_type.is_valid(new_value): inferred_type = SegmentType.infer_segment_type(new_value) raise ConversationVariableTypeMismatchError(