You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it will raise unwanted validation type error when a model has many optional field;
pydantic won't raise any error
from odmantic import Model,Field
from pydantic import BaseModel
from typing import Optional, Dict
class DummpyEmbedModel(Model):
"""item url and title, thumbnail
treat as task queue
"""
infos: Optional[Dict] = None
# all image text in item page
pso: Optional[str] = None
gptTags: Optional[Dict] = None
Current Behavior
self = DummpyEmbedModel(), data = {'infos': {}, 'pso': 'xx'}
def __init__(self, **data: Any):
> super().__init__(**data)
E pydantic_core._pydantic_core.ValidationError: 1 validation error for DummpyEmbedModel
E pso
E Input should be a valid dictionary [type=dict_type, input_value='xx', input_type=str]
E For further information visit https://errors.pydantic.dev/2.5/v/dict_type
Expected behavior
should no raise any error as pydantic
Environment
ODMantic version: ...
MongoDB version: ...
Pydantic infos (output of python -c "import pydantic.utils; print(pydantic.utils.version_info())):
class DummpyEmbedModel(Model):
"""item url and title, thumbnail
treat as task queue
"""
infos: Optional[Dict] = None
# all image text in item page
pso: Optional[str] = None
gptTags: Optional[Dict] = None
...
Version of additional modules (if relevant):
...
Additional context
v1.0.0
The text was updated successfully, but these errors were encountered:
@laveolus and @brightgems and @Jibola, until this is addressed, have you found any temporary workaround to this? I also encountered same.
Currently, I have just leveraged the Pydantic BaseModel class as my workaround for now. If it's unavoidable, I've settled for removing the Optional field usage.
Bug
it will raise unwanted validation type error when a model has many optional field;
pydantic won't raise any error
from odmantic import Model,Field
from pydantic import BaseModel
from typing import Optional, Dict
class DummpyEmbedModel(Model):
"""item url and title, thumbnail
treat as task queue
"""
infos: Optional[Dict] = None
# all image text in item page
pso: Optional[str] = None
gptTags: Optional[Dict] = None
Current Behavior
Expected behavior
should no raise any error as pydantic
Environment
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):Additional context
v1.0.0
The text was updated successfully, but these errors were encountered: