diff --git a/core/cat/experimental/form/cat_form.py b/core/cat/experimental/form/cat_form.py index 8c13061e..79a49df0 100644 --- a/core/cat/experimental/form/cat_form.py +++ b/core/cat/experimental/form/cat_form.py @@ -39,6 +39,9 @@ def __init__(self, cat) -> None: def cat(self): return self._cat + def model_getter(self): + return self.model_class + def submit(self, form_data) -> str: raise NotImplementedError @@ -124,7 +127,7 @@ def next(self): # If the state is INCOMPLETE, execute model update # (and change state based on validation result) if self._state == CatFormState.INCOMPLETE: - self._model = self.update() + self.update() # If state is COMPLETE, ask confirm (or execute action directly) if self._state == CatFormState.COMPLETE: @@ -145,12 +148,11 @@ def update(self): json_details = self.sanitize(json_details) # model merge old and new - new_model = self._model | json_details + self._model = self._model | json_details # Validate new_details - new_model = self.validate(new_model) + self.validate() - return new_model def message(self): state_methods = { @@ -219,7 +221,7 @@ def extraction_prompt(self): # JSON structure # BaseModel.__fields__['my_field'].type_ JSON_structure = "{" - for field_name, field in self.model_class.model_fields.items(): + for field_name, field in self.model_getter().model_fields.items(): if field.description: description = field.description else: @@ -260,7 +262,7 @@ def sanitize(self, model): return model # Validate model - def validate(self, model): + def validate(self): self._missing_fields = [] self._errors = [] @@ -268,7 +270,7 @@ def validate(self, model): # INFO TODO: In this case the optional fields are always ignored # Attempts to create the model object to update the default values and validate it - model = self.model_class(**model).model_dump(mode="json") + self.model_getter()(**self._model).model_dump(mode="json") # If model is valid change state to COMPLETE self._state = CatFormState.COMPLETE @@ -281,9 +283,7 @@ def validate(self, model): self._missing_fields.append(field_name) else: self._errors.append(f'{field_name}: {error_message["msg"]}') - del model[field_name] + del self._model[field_name] # Set state to INCOMPLETE - self._state = CatFormState.INCOMPLETE - - return model + self._state = CatFormState.INCOMPLETE \ No newline at end of file