Open miyagipipi opened 3 hours ago
@miyagipipi Hello! I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's tackle this issue together!
To handle an unfilled optional number variable in Dify version 0.11.1, you can set it to None
or a default value. The code in code_node.py
shows that when a variable is not provided, it is set to None
:
variables[variable_name] = variable.to_object() if variable else None
Additionally, the _check_number
method allows None
as a valid value for a number variable:
def _check_number(self, value: Union[int, float], variable: str) -> Union[int, float]:
if not isinstance(value, int | float):
if value is None:
return None
else:
raise OutputValidationError(f"Output variable `{variable}` must be a number")
...
This means that if the variable is not filled, it will be set to None
and will not cause an error. If you want to set a default value instead of None
, you can modify the code where the variable is assigned:
variables[variable_name] = variable.to_object() if variable else default_value
Replace default_value
with the desired default number [1].
To continue talking to Dosu, mention @dosu.
Can't reproduce.
@crazywoola I know the reason about this error. First i input a number in this optional variable, then i delete it and run. In this case, this error happen, and the variable becomes empty string.
Self Checks
Dify version
Version 0.11.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
I set a optional number variable。 When I run without this variable, dify reports an error and displays "word_num in input form must be a valid number". Word_num is my number variable name. My dify version is 0.11.1 and i had read https://github.com/langgenius/dify/pull/10529. I hope that the unfilled optional variable can be handled correctly here. (ex set it null?)
✔️ Expected Behavior
unfilled optional number variable can be set as null or default?
❌ Actual Behavior
unfilled optional number variable in input form must be a valid number