fix: Dict Input Validation issue in Dynamic Components (#7754)
* Update inputs.py * update dict validation approach * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
2ea2bb01ed
commit
0a628e1fb1
2 changed files with 12 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from ast import literal_eval
|
||||
from datetime import timedelta
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Annotated, Any
|
||||
|
|
@ -280,11 +281,18 @@ def get_suggestion_message(outdated_components: list[str]) -> str:
|
|||
def parse_value(value: Any, input_type: str) -> Any:
|
||||
"""Helper function to parse the value based on input type."""
|
||||
if value == "":
|
||||
return value
|
||||
return {} if input_type == "DictInput" else value
|
||||
if input_type == "IntInput":
|
||||
return int(value) if value is not None else None
|
||||
if input_type == "FloatInput":
|
||||
return float(value) if value is not None else None
|
||||
if input_type == "DictInput":
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
try:
|
||||
return literal_eval(value) if value is not None else {}
|
||||
except (ValueError, SyntaxError):
|
||||
return {}
|
||||
return value
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -458,7 +458,9 @@ class DictInput(BaseInputMixin, ListableInputMixin, InputTraceMixin, ToolModeMix
|
|||
"""
|
||||
|
||||
field_type: SerializableFieldTypes = FieldTypes.DICT
|
||||
value: dict | None = {}
|
||||
# Note do not set value to an empty dict, it will break the component in dynamic update build config
|
||||
# value: dict | None = {}
|
||||
value: dict = Field(default_factory=dict)
|
||||
|
||||
|
||||
class DropdownInput(BaseInputMixin, DropDownMixin, MetadataTraceMixin, ToolModeMixin):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue