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
A clear and concise description of what the bug is.
Pydantic has a nice feature around computed fields that allow you to create an attribute based on logic in other fields, however these fields are not added to Model.__odm_fields__ which means they don't get used when running engine.save(Model)
If you add a ODMBaseField to Model.__odm_fields__ it will include it, but this is very hacky and shouldn't be the right way to do this.
Bug
A clear and concise description of what the bug is.
Pydantic has a nice feature around computed fields that allow you to create an attribute based on logic in other fields, however these fields are not added to
Model.__odm_fields__
which means they don't get used when running engine.save(Model)If you add a ODMBaseField to
Model.__odm_fields__
it will include it, but this is very hacky and shouldn't be the right way to do this.Current Behavior
then the data in the collection is
{"data_from_user":"foo"}
Expected behavior
then the data in the collection would be
{"data_from_user":"foo", "computed_data":"bar"}
Environment
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):pydantic version: 2.5.3
pydantic-core version: 2.14.6
pydantic-core build: profile=release pgo=true
install path: /home/lucastieman/PycharmProjects/monorepo/venv/lib/python3.11/site-packages/pydantic
python version: 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)]
platform: Linux-6.6.3-100.fc38.x86_64-x86_64-with-glibc2.37
related packages: typing_extensions-4.8.0 fastapi-0.104.1 email-validator-2.1.0.post1
The text was updated successfully, but these errors were encountered: