refactor: Update BaseInputMixin to validate input assignment
This commit is contained in:
parent
4df46bf9de
commit
c97d90c4ad
2 changed files with 3 additions and 5 deletions
|
|
@ -11,7 +11,6 @@ from langflow.inputs.inputs import InputTypes
|
||||||
from langflow.schema.artifact import get_artifact_type, post_process_raw
|
from langflow.schema.artifact import get_artifact_type, post_process_raw
|
||||||
from langflow.schema.data import Data
|
from langflow.schema.data import Data
|
||||||
from langflow.template.field.base import UNDEFINED, Input, Output
|
from langflow.template.field.base import UNDEFINED, Input, Output
|
||||||
from langflow.utils.util import is_class_method
|
|
||||||
|
|
||||||
from .custom_component import CustomComponent
|
from .custom_component import CustomComponent
|
||||||
|
|
||||||
|
|
@ -63,9 +62,8 @@ class Component(CustomComponent):
|
||||||
if key not in self._inputs:
|
if key not in self._inputs:
|
||||||
raise ValueError(f"Input {key} not found in arguments")
|
raise ValueError(f"Input {key} not found in arguments")
|
||||||
input_ = self._inputs[key]
|
input_ = self._inputs[key]
|
||||||
# validate_inputs must be a classmethod
|
# BaseInputMixin has a `validate_assignment=True`
|
||||||
if hasattr(input_, "validate_value") and is_class_method(func=input_.validate_value, cls=input_):
|
input_.value = value
|
||||||
input_.validate_value(value)
|
|
||||||
|
|
||||||
def set_attributes(self, params: dict):
|
def set_attributes(self, params: dict):
|
||||||
self._validate_inputs(params)
|
self._validate_inputs(params)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ SerializableFieldTypes = Annotated[FieldTypes, PlainSerializer(lambda v: v.value
|
||||||
|
|
||||||
|
|
||||||
# Base mixin for common input field attributes and methods
|
# Base mixin for common input field attributes and methods
|
||||||
class BaseInputMixin(BaseModel):
|
class BaseInputMixin(BaseModel, validate_assignment=True):
|
||||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|
||||||
field_type: Optional[SerializableFieldTypes | str] = Field(default=FieldTypes.TEXT)
|
field_type: Optional[SerializableFieldTypes | str] = Field(default=FieldTypes.TEXT)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue