Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] pydantic computed properties omitted during insert_many operation on Document #933

Open
aksswami opened this issue May 14, 2024 · 0 comments

Comments

@aksswami
Copy link

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

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.

@aksswami 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant