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
Describe the bug
Pydantic V2 have a bug where __iter__ does not include computed property. pydantic/pydantic#8564
This cause the document to omit the computed properties during insert, as Encoder is using __iter__ to get all properties.
To Reproduce
frombeanieimportDocumentclassTestModel(Document):
normal: int@pydantic.computed_field@propertydefcomputed(self) ->int:
return1instance=TestModel(normal=42)
assert {field: valueforfield, valueininstance} ==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.
The text was updated successfully, but these errors were encountered:
aksswami
changed the title
[BUG] pydantic computed properties ommited during insert_many operation on Document.
[BUG] pydantic computed properties omitted during insert_many operation on Document
May 14, 2024
Describe the bug
Pydantic V2 have a bug where
__iter__
does not include computed property. pydantic/pydantic#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
.The text was updated successfully, but these errors were encountered: