Fix Config.plugins_config - call model_post_init explicitly until pydantic 2.0 (#4858)

As per
https://github.com/pydantic/pydantic/issues/1729#issuecomment-1300576214,
the implementation of `model_post_init()` is postponed until Pydantic
v2. As a result, the initialization of PluginConfig is being skipped.

This fix calls `plugin.model_post_init()` explicitly.

The recency of the Pydantic v2 release means that some of the other
extensions we use do not support it yet. Specifically, extensions such
as spacy and openapi-python-client are currently limited to Pydantic
versions that are less than 2.0. There may be other extensions that have
the same limitation as well.

---------

Co-authored-by: Reinier van der Leer <github@pwuts.nl>
This commit is contained in:
Luke
2023-07-04 17:55:00 -04:00
committed by GitHub
parent c67940edec
commit 7e45b6a975

View File

@@ -83,6 +83,13 @@ class Config(SystemSettings):
plugins: list[str]
authorise_key: str
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Hotfix: Call model_post_init explictly as it doesn't seem to be called for pydantic<2.0.0
# https://github.com/pydantic/pydantic/issues/1729#issuecomment-1300576214
self.model_post_init(**kwargs)
# Executed immediately after init by Pydantic
def model_post_init(self, **kwargs) -> None:
if not self.plugins_config.plugins: