Pārlūkot izejas kodu

optimize: code node has a bad error message (#3949)

tags/0.6.6
Yeuoly pirms 1 gada
vecāks
revīzija
e7b4d024ee
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 8
- 8
api/core/workflow/nodes/code/code_node.py Parādīt failu

:return: :return:
""" """
if not isinstance(value, str): if not isinstance(value, str):
raise ValueError(f"{variable} in output form must be a string")
raise ValueError(f"Output variable `{variable}` must be a string")


if len(value) > MAX_STRING_LENGTH: if len(value) > MAX_STRING_LENGTH:
raise ValueError(f'{variable} in output form must be less than {MAX_STRING_LENGTH} characters')
raise ValueError(f'The length of output variable `{variable}` must be less than {MAX_STRING_LENGTH} characters')


return value.replace('\x00', '') return value.replace('\x00', '')


:return: :return:
""" """
if not isinstance(value, int | float): if not isinstance(value, int | float):
raise ValueError(f"{variable} in output form must be a number")
raise ValueError(f"Output variable `{variable}` must be a number")


if value > MAX_NUMBER or value < MIN_NUMBER: if value > MAX_NUMBER or value < MIN_NUMBER:
raise ValueError(f'{variable} in input form is out of range.')
raise ValueError(f'Output variable `{variable}` is out of range, it must be between {MIN_NUMBER} and {MAX_NUMBER}.')


if isinstance(value, float): if isinstance(value, float):
# raise error if precision is too high # raise error if precision is too high
if len(str(value).split('.')[1]) > MAX_PRECISION: if len(str(value).split('.')[1]) > MAX_PRECISION:
raise ValueError(f'{variable} in output form has too high precision.')
raise ValueError(f'Output variable `{variable}` has too high precision, it must be less than {MAX_PRECISION} digits.')


return value return value




if len(result[output_name]) > MAX_NUMBER_ARRAY_LENGTH: if len(result[output_name]) > MAX_NUMBER_ARRAY_LENGTH:
raise ValueError( raise ValueError(
f'{prefix}{dot}{output_name} in output form must be less than {MAX_NUMBER_ARRAY_LENGTH} characters.'
f'The length of output variable `{prefix}{dot}{output_name}` must be less than {MAX_NUMBER_ARRAY_LENGTH} elements.'
) )


transformed_result[output_name] = [ transformed_result[output_name] = [


if len(result[output_name]) > MAX_STRING_ARRAY_LENGTH: if len(result[output_name]) > MAX_STRING_ARRAY_LENGTH:
raise ValueError( raise ValueError(
f'{prefix}{dot}{output_name} in output form must be less than {MAX_STRING_ARRAY_LENGTH} characters.'
f'The length of output variable `{prefix}{dot}{output_name}` must be less than {MAX_STRING_ARRAY_LENGTH} elements.'
) )


transformed_result[output_name] = [ transformed_result[output_name] = [


if len(result[output_name]) > MAX_OBJECT_ARRAY_LENGTH: if len(result[output_name]) > MAX_OBJECT_ARRAY_LENGTH:
raise ValueError( raise ValueError(
f'{prefix}{dot}{output_name} in output form must be less than {MAX_OBJECT_ARRAY_LENGTH} characters.'
f'The length of output variable `{prefix}{dot}{output_name}` must be less than {MAX_OBJECT_ARRAY_LENGTH} elements.'
) )
for i, value in enumerate(result[output_name]): for i, value in enumerate(result[output_name]):

+ 1
- 1
api/tests/integration_tests/workflow/nodes/test_code.py Parādīt failu

result = node.run(pool) result = node.run(pool)


assert result.status == WorkflowNodeExecutionStatus.FAILED assert result.status == WorkflowNodeExecutionStatus.FAILED
assert result.error == 'result in output form must be a string'
assert result.error == 'Output variable `result` must be a string'


def test_execute_code_output_validator_depth(): def test_execute_code_output_validator_depth():
code = ''' code = '''

Notiek ielāde…
Atcelt
Saglabāt