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:
Edwin Jose 2025-04-29 00:33:27 -04:00 committed by GitHub
commit 0a628e1fb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -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

View file

@ -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):