fix: correct type checking for None values in code node output validation

- Fixed isinstance() checks to properly handle None values by checking None separately
- Fixed typo in STRING type validation where 'output_name' was hardcoded as string instead of variable
- Updated error message format to be consistent and more informative
- Updated test assertion to match new error message format
This commit is contained in:
-LAN- 2025-09-04 20:39:37 +08:00
parent 9c2943183e
commit 81e9d6f63a
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF
2 changed files with 7 additions and 5 deletions

View File

@ -256,7 +256,7 @@ class CodeNode(Node):
elif output_config.type == SegmentType.NUMBER:
# check if number available
value = result.get(output_name)
if not isinstance(value, (int, float, None)):
if value is not None and not isinstance(value, (int, float)):
raise OutputValidationError(
f"Output {prefix}{dot}{output_name} is not a number,"
f" got {type(result.get(output_name))} instead."
@ -271,9 +271,11 @@ class CodeNode(Node):
elif output_config.type == SegmentType.STRING:
# check if string available
value = result.get("output_name")
value = result.get(output_name)
if value is not None and not isinstance(value, str):
raise OutputValidationError(f"Output value `{value}` is not string")
raise OutputValidationError(
f"Output {prefix}{dot}{output_name} must be a string, got {type(value).__name__} instead"
)
transformed_result[output_name] = self._check_string(
value=value,
variable=f"{prefix}{dot}{output_name}",
@ -388,7 +390,7 @@ class CodeNode(Node):
)
else:
for i, inner_value in enumerate(value):
if not isinstance(inner_value, bool | None):
if inner_value is not None and not isinstance(inner_value, bool):
raise OutputValidationError(
f"Output {prefix}{dot}{output_name}[{i}] is not a boolean,"
f" got {type(inner_value)} instead."

View File

@ -162,7 +162,7 @@ def test_execute_code_output_validator(setup_code_executor_mock):
result = node._run()
assert isinstance(result, NodeRunResult)
assert result.status == WorkflowNodeExecutionStatus.FAILED
assert result.error == "Output variable `result` must be a string"
assert result.error == "Output result must be a string, got int instead"
def test_execute_code_output_validator_depth():