refactor: convert SegmentType controllers if/elif to match/case (#30001) (#34784)

This commit is contained in:
dataCenter430 2026-04-08 18:11:47 -07:00 committed by GitHub
parent 3325392cc5
commit 1c7cf44af4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 50 deletions

View File

@ -384,24 +384,27 @@ class VariableApi(Resource):
new_value = None new_value = None
if raw_value is not None: if raw_value is not None:
if variable.value_type == SegmentType.FILE: match variable.value_type:
if not isinstance(raw_value, dict): case SegmentType.FILE:
raise InvalidArgumentError(description=f"expected dict for file, got {type(raw_value)}") if not isinstance(raw_value, dict):
raw_value = build_from_mapping( raise InvalidArgumentError(description=f"expected dict for file, got {type(raw_value)}")
mapping=raw_value, raw_value = build_from_mapping(
tenant_id=app_model.tenant_id, mapping=raw_value,
access_controller=_file_access_controller, tenant_id=app_model.tenant_id,
) access_controller=_file_access_controller,
elif variable.value_type == SegmentType.ARRAY_FILE: )
if not isinstance(raw_value, list): case SegmentType.ARRAY_FILE:
raise InvalidArgumentError(description=f"expected list for files, got {type(raw_value)}") if not isinstance(raw_value, list):
if len(raw_value) > 0 and not isinstance(raw_value[0], dict): raise InvalidArgumentError(description=f"expected list for files, got {type(raw_value)}")
raise InvalidArgumentError(description=f"expected dict for files[0], got {type(raw_value)}") if len(raw_value) > 0 and not isinstance(raw_value[0], dict):
raw_value = build_from_mappings( raise InvalidArgumentError(description=f"expected dict for files[0], got {type(raw_value)}")
mappings=raw_value, raw_value = build_from_mappings(
tenant_id=app_model.tenant_id, mappings=raw_value,
access_controller=_file_access_controller, tenant_id=app_model.tenant_id,
) access_controller=_file_access_controller,
)
case _:
pass
new_value = build_segment_with_type(variable.value_type, raw_value) new_value = build_segment_with_type(variable.value_type, raw_value)
draft_var_srv.update_variable(variable, name=new_name, value=new_value) draft_var_srv.update_variable(variable, name=new_name, value=new_value)
db.session.commit() db.session.commit()

View File

@ -223,24 +223,27 @@ class RagPipelineVariableApi(Resource):
new_value = None new_value = None
if raw_value is not None: if raw_value is not None:
if variable.value_type == SegmentType.FILE: match variable.value_type:
if not isinstance(raw_value, dict): case SegmentType.FILE:
raise InvalidArgumentError(description=f"expected dict for file, got {type(raw_value)}") if not isinstance(raw_value, dict):
raw_value = build_from_mapping( raise InvalidArgumentError(description=f"expected dict for file, got {type(raw_value)}")
mapping=raw_value, raw_value = build_from_mapping(
tenant_id=pipeline.tenant_id, mapping=raw_value,
access_controller=_file_access_controller, tenant_id=pipeline.tenant_id,
) access_controller=_file_access_controller,
elif variable.value_type == SegmentType.ARRAY_FILE: )
if not isinstance(raw_value, list): case SegmentType.ARRAY_FILE:
raise InvalidArgumentError(description=f"expected list for files, got {type(raw_value)}") if not isinstance(raw_value, list):
if len(raw_value) > 0 and not isinstance(raw_value[0], dict): raise InvalidArgumentError(description=f"expected list for files, got {type(raw_value)}")
raise InvalidArgumentError(description=f"expected dict for files[0], got {type(raw_value)}") if len(raw_value) > 0 and not isinstance(raw_value[0], dict):
raw_value = build_from_mappings( raise InvalidArgumentError(description=f"expected dict for files[0], got {type(raw_value)}")
mappings=raw_value, raw_value = build_from_mappings(
tenant_id=pipeline.tenant_id, mappings=raw_value,
access_controller=_file_access_controller, tenant_id=pipeline.tenant_id,
) access_controller=_file_access_controller,
)
case _:
pass
new_value = build_segment_with_type(variable.value_type, raw_value) new_value = build_segment_with_type(variable.value_type, raw_value)
draft_var_srv.update_variable(variable, name=new_name, value=new_value) draft_var_srv.update_variable(variable, name=new_name, value=new_value)
db.session.commit() db.session.commit()

View File

@ -155,24 +155,25 @@ class TriggerWebhookNode(Node[WebhookData]):
outputs[param_name] = raw_data outputs[param_name] = raw_data
continue continue
if param_type == SegmentType.FILE: match param_type:
# Get File object (already processed by webhook controller) case SegmentType.FILE:
files = webhook_data.get("files", {}) # Get File object (already processed by webhook controller)
if files and isinstance(files, dict): files = webhook_data.get("files", {})
file = files.get(param_name) if files and isinstance(files, dict):
if file and isinstance(file, dict): file = files.get(param_name)
file_var = self.generate_file_var(param_name, file) if file and isinstance(file, dict):
if file_var: file_var = self.generate_file_var(param_name, file)
outputs[param_name] = file_var if file_var:
outputs[param_name] = file_var
else:
outputs[param_name] = files
else: else:
outputs[param_name] = files outputs[param_name] = files
else: else:
outputs[param_name] = files outputs[param_name] = files
else: case _:
outputs[param_name] = files # Get regular body parameter
else: outputs[param_name] = webhook_data.get("body", {}).get(param_name)
# Get regular body parameter
outputs[param_name] = webhook_data.get("body", {}).get(param_name)
# Include raw webhook data for debugging/advanced use # Include raw webhook data for debugging/advanced use
outputs["_webhook_raw"] = webhook_data outputs["_webhook_raw"] = webhook_data