model_config = ConfigDict(extra='allow') (#24859)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
f70272f638
commit
cb04c21141
1 changed files with 4 additions and 2 deletions
|
|
@ -1,12 +1,14 @@
|
||||||
from pydantic import BaseModel, Field, ValidationError
|
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
||||||
|
|
||||||
|
|
||||||
class MoreLikeThisConfig(BaseModel):
|
class MoreLikeThisConfig(BaseModel):
|
||||||
enabled: bool = False
|
enabled: bool = False
|
||||||
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
class AppConfigModel(BaseModel):
|
class AppConfigModel(BaseModel):
|
||||||
more_like_this: MoreLikeThisConfig = Field(default_factory=MoreLikeThisConfig)
|
more_like_this: MoreLikeThisConfig = Field(default_factory=MoreLikeThisConfig)
|
||||||
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
class MoreLikeThisConfigManager:
|
class MoreLikeThisConfigManager:
|
||||||
|
|
@ -23,7 +25,7 @@ class MoreLikeThisConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
||||||
try:
|
try:
|
||||||
return AppConfigModel.model_validate(config).dict(), ["more_like_this"]
|
return AppConfigModel.model_validate(config).model_dump(), ["more_like_this"]
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"more_like_this must be of dict type and enabled in more_like_this must be of boolean type"
|
"more_like_this must be of dict type and enabled in more_like_this must be of boolean type"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue