@@ -420,10 +420,10 @@ def get_decrypted_tracing_config(cls, app_id: str, tracing_provider: str):
420420 :param tracing_provider: tracing provider
421421 :return:
422422 """
423- trace_config_data : TraceAppConfig | None = (
424- db . session . query (TraceAppConfig )
423+ trace_config_data : TraceAppConfig | None = db . session . scalar (
424+ select (TraceAppConfig )
425425 .where (TraceAppConfig .app_id == app_id , TraceAppConfig .tracing_provider == tracing_provider )
426- .first ( )
426+ .limit ( 1 )
427427 )
428428
429429 if not trace_config_data :
@@ -463,7 +463,7 @@ def get_ops_trace_instance(
463463 if isinstance (app_id , str ) and app_id .startswith ("tenant-" ):
464464 return None
465465
466- app : App | None = db .session .query (App ). where ( App . id == app_id ). first ( )
466+ app = db .session .get (App , app_id )
467467
468468 if app is None :
469469 return None
@@ -537,7 +537,7 @@ def update_app_tracing_config(cls, app_id: str, enabled: bool, tracing_provider:
537537 except KeyError :
538538 raise ValueError (f"Invalid tracing provider: { tracing_provider } " )
539539
540- app_config : App | None = db .session .query (App ). where ( App . id == app_id ). first ( )
540+ app_config : App | None = db .session .get (App , app_id )
541541 if not app_config :
542542 raise ValueError ("App not found" )
543543 app_config .tracing = json .dumps (
@@ -555,7 +555,7 @@ def get_app_tracing_config(cls, app_id: str):
555555 :param app_id: app id
556556 :return:
557557 """
558- app : App | None = db .session .query (App ). where ( App . id == app_id ). first ( )
558+ app : App | None = db .session .get (App , app_id )
559559 if not app :
560560 raise ValueError ("App not found" )
561561 if not app .tracing :
@@ -883,7 +883,7 @@ def message_trace(self, message_id: str | None, **kwargs):
883883 inputs = message_data .message
884884
885885 # get message file data
886- message_file_data = db .session .query ( MessageFile ).filter_by ( message_id = message_id ).first ( )
886+ message_file_data = db .session .scalar ( select ( MessageFile ).where ( MessageFile . message_id == message_id ).limit ( 1 ) )
887887 file_list = []
888888 if message_file_data and message_file_data .url is not None :
889889 file_url = f"{ self .file_base_url } /{ message_file_data .url } " if message_file_data else ""
@@ -972,8 +972,8 @@ def moderation_trace(self, message_id, timer, **kwargs):
972972 # get workflow_app_log_id
973973 workflow_app_log_id = None
974974 if message_data .workflow_run_id :
975- workflow_app_log_data = (
976- db . session . query (WorkflowAppLog ).filter_by ( workflow_run_id = message_data .workflow_run_id ).first ( )
975+ workflow_app_log_data = db . session . scalar (
976+ select (WorkflowAppLog ).where ( WorkflowAppLog . workflow_run_id == message_data .workflow_run_id ).limit ( 1 )
977977 )
978978 workflow_app_log_id = str (workflow_app_log_data .id ) if workflow_app_log_data else None
979979
@@ -1015,8 +1015,8 @@ def suggested_question_trace(self, message_id, timer, **kwargs):
10151015 # get workflow_app_log_id
10161016 workflow_app_log_id = None
10171017 if message_data .workflow_run_id :
1018- workflow_app_log_data = (
1019- db . session . query (WorkflowAppLog ).filter_by ( workflow_run_id = message_data .workflow_run_id ).first ( )
1018+ workflow_app_log_data = db . session . scalar (
1019+ select (WorkflowAppLog ).where ( WorkflowAppLog . workflow_run_id == message_data .workflow_run_id ).limit ( 1 )
10201020 )
10211021 workflow_app_log_id = str (workflow_app_log_data .id ) if workflow_app_log_data else None
10221022
@@ -1171,7 +1171,7 @@ def tool_trace(self, message_id, timer, **kwargs):
11711171 metadata ["node_execution_id" ] = node_execution_id
11721172
11731173 file_url = ""
1174- message_file_data = db .session .query ( MessageFile ).filter_by ( message_id = message_id ).first ( )
1174+ message_file_data = db .session .scalar ( select ( MessageFile ).where ( MessageFile . message_id == message_id ).limit ( 1 ) )
11751175 if message_file_data :
11761176 message_file_id = message_file_data .id if message_file_data else None
11771177 type = message_file_data .type
0 commit comments