acederberg / pydantic-settings-yaml

A convenient tool for loading pydantic settings from either YAML and JSON.
MIT License
5 stars 3 forks source link

BaseYamlSettings is not compatible with pydantic 2.7 #19

Closed ZeeD closed 5 months ago

ZeeD commented 6 months ago

example taken from readme.md:

from yaml_settings_pydantic import BaseYamlSettings
from yaml_settings_pydantic import YamlSettingsConfigDict

class MySettings(BaseYamlSettings):
    model_config = YamlSettingsConfigDict(yaml_files="settings.yaml")

    setttingOne: str
    settingTwo: str

raises this error with current pydantic (everything works with 2.6.x)

    class BaseYamlSettings(BaseSettings):
  File ".../.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 91, in __new__
    config_wrapper = ConfigWrapper.for_model(bases, namespace, kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/pydantic/_internal/_config.py", line 122, in for_model
    raise PydanticUserError(
pydantic.errors.PydanticUserError: `model_config` cannot be used as a model field name. Use `model_config` for model configuration.

For further information visit https://errors.pydantic.dev/2.7/u/model-config-invalid-field-name