This cause the document to omit the computed properties during insert, as Encoder is using __iter__ to get all properties.
To Reproduce
from beanie import Document
class TestModel(Document):
normal: int
@pydantic.computed_field
@property
def computed(self) -> int:
return 1
instance = TestModel(normal=42)
assert {field: value for field, value in instance} == instance.model_dump() # fails
# or
TestModel.insert_many([instance]) # This document in mongo will omit `computed` property.
Expected behavior
Expect all properties to be included during the insert operation.
Additional context
As this issue is still open on pydantic, not sure if we need to wait for a fix from pydantic.
Describe the bug Pydantic V2 have a bug where
__iter__
does not include computed property. https://github.com/pydantic/pydantic/issues/8564This cause the document to omit the computed properties during insert, as
Encoder
is using__iter__
to get all properties.To Reproduce
Expected behavior Expect all properties to be included during the insert operation.
Additional context As this issue is still open on
pydantic
, not sure if we need to wait for a fix frompydantic
.