From b8c63eba860fe11961bddd9a08b193b2b5ac35b9 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 22 Jul 2026 12:29:29 +0800 Subject: [PATCH] fix: ignore unknown config.yaml keys instead of crashing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit main's ConfigLoader never validated the YAML's own keys — config.yaml defined the legal key set and unknown entries merged harmlessly into the SimpleNamespace. Wiring the YAML into IndexConfig (f995e64) inherited c7fe93b's extra=forbid, inverting that: any deprecated or user-added key now raised an uncaught ValidationError from the CLI and ConfigLoader. Filter YAML data to known fields with a warning; explicit keyword overrides keep strict validation. --- pageindex/config.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pageindex/config.py b/pageindex/config.py index 9b8d21d..3433860 100644 --- a/pageindex/config.py +++ b/pageindex/config.py @@ -50,12 +50,20 @@ class IndexConfig(BaseModel): @classmethod def from_yaml(cls, path: str = None, **overrides) -> "IndexConfig": """Load config from a YAML file ("yes"/"no" accepted for booleans); - keyword overrides take precedence. Defaults to the package config.yaml.""" + keyword overrides take precedence. Defaults to the package config.yaml. + Unknown YAML keys are ignored with a warning (legacy config.yaml + tolerance); unknown keyword overrides still raise.""" import yaml if path is None: path = os.path.join(os.path.dirname(__file__), "config.yaml") with open(path, "r", encoding="utf-8") as f: data = yaml.safe_load(f) or {} + unknown = set(data) - set(cls.model_fields) + if unknown: + import logging + logging.getLogger(__name__).warning( + "Ignoring unknown config.yaml keys: %s", sorted(unknown)) + data = {k: v for k, v in data.items() if k not in unknown} return cls(**{**data, **overrides})