Skip to content

Commit

Permalink
add a class method _exclude_from_validation to enable bypassing the…
Browse files Browse the repository at this point in the history
… `raise_error_for_unknown_keywords`
  • Loading branch information
MAfarrag committed Dec 18, 2024
1 parent fe27aee commit 297d919
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hydrolib/core/dflowfm/ini/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ class Config:
@root_validator(pre=True)
def _validate_unknown_keywords(cls, values):
unknown_keyword_error_manager = cls._get_unknown_keyword_error_manager()
do_not_validate = cls._exclude_from_validation(values)
if unknown_keyword_error_manager:
unknown_keyword_error_manager.raise_error_for_unknown_keywords(
values,
cls._header,
cls.__fields__,
cls._exclude_fields(),
cls._exclude_fields() | do_not_validate,
)
return values

Expand Down Expand Up @@ -188,6 +189,11 @@ def validate(cls: Type["INIBasedModel"], value: Any) -> "INIBasedModel":

return super().validate(value)

@classmethod
def _exclude_from_validation(cls, input_data: Optional = None) -> Set:
"""Fields that should not be checked when validating existing fields as they will be dynamically added."""
return set()

@classmethod
def _exclude_fields(cls) -> Set:
return {"comments", "datablock", "_header"}
Expand Down

0 comments on commit 297d919

Please sign in to comment.