fix: ignore unknown config.yaml keys instead of crashing

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.
This commit is contained in:
Ray 2026-07-22 12:29:29 +08:00
parent a9bb019d05
commit b8c63eba86

View file

@ -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})