fix for obsolete pydantic parameters
This commit is contained in:
@ -8,6 +8,7 @@ from ormar.models.helpers.pydantic import (
|
||||
get_potential_fields,
|
||||
get_pydantic_base_orm_config,
|
||||
get_pydantic_field,
|
||||
merge_or_generate_pydantic_config,
|
||||
remove_excluded_parent_fields,
|
||||
)
|
||||
from ormar.models.helpers.relations import (
|
||||
@ -33,6 +34,7 @@ __all__ = [
|
||||
"get_pydantic_field",
|
||||
"get_potential_fields",
|
||||
"get_pydantic_base_orm_config",
|
||||
"merge_or_generate_pydantic_config",
|
||||
"check_required_meta_parameters",
|
||||
"sqlalchemy_columns_from_model_fields",
|
||||
"populate_choices_validators",
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import inspect
|
||||
from typing import Dict, Optional, TYPE_CHECKING, Tuple, Type
|
||||
|
||||
import pydantic
|
||||
@ -5,6 +6,7 @@ from pydantic.fields import ModelField
|
||||
from pydantic.utils import lenient_issubclass
|
||||
|
||||
from ormar.fields import BaseField # noqa: I100, I202
|
||||
from ormar.exceptions import ModelDefinitionError
|
||||
|
||||
if TYPE_CHECKING: # pragma no cover
|
||||
from ormar import Model
|
||||
@ -88,6 +90,31 @@ def populate_pydantic_default_values(attrs: Dict) -> Tuple[Dict, Dict]:
|
||||
return attrs, model_fields
|
||||
|
||||
|
||||
def merge_or_generate_pydantic_config(attrs: Dict, name: str) -> None:
|
||||
"""
|
||||
Checks if the user provided pydantic Config,
|
||||
and if he did merges it with the default one.
|
||||
|
||||
Updates the attrs in place with a new config.
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
DefaultConfig = get_pydantic_base_orm_config()
|
||||
if "Config" in attrs:
|
||||
ProvidedConfig = attrs["Config"]
|
||||
if not inspect.isclass(ProvidedConfig):
|
||||
raise ModelDefinitionError(
|
||||
f"Config provided for class {name} has to be a class."
|
||||
)
|
||||
|
||||
class Config(ProvidedConfig, DefaultConfig): # type: ignore
|
||||
pass
|
||||
|
||||
attrs["Config"] = Config
|
||||
else:
|
||||
attrs["Config"] = DefaultConfig
|
||||
|
||||
|
||||
def get_pydantic_base_orm_config() -> Type[pydantic.BaseConfig]:
|
||||
"""
|
||||
Returns empty pydantic Config with orm_mode set to True.
|
||||
|
||||
Reference in New Issue
Block a user