From 297d919bc3148c4ee3d092fc77ac72ba6b5d8dd6 Mon Sep 17 00:00:00 2001 From: MAFarrag Date: Wed, 18 Dec 2024 16:52:49 +0100 Subject: [PATCH] add a class method `_exclude_from_validation` to enable bypassing the `raise_error_for_unknown_keywords` --- hydrolib/core/dflowfm/ini/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hydrolib/core/dflowfm/ini/models.py b/hydrolib/core/dflowfm/ini/models.py index 76fa1631a..58ad95d3d 100644 --- a/hydrolib/core/dflowfm/ini/models.py +++ b/hydrolib/core/dflowfm/ini/models.py @@ -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 @@ -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"}