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

Using Model.model_construct breaks attr setters #486

Open
nernst opened this issue May 30, 2024 · 0 comments
Open

Using Model.model_construct breaks attr setters #486

nernst opened this issue May 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nernst
Copy link

nernst commented May 30, 2024

Bug

Attempting to create a model instance using Model.model_construct results in __fields_modified__ not being present on the instance, causing AttributeErrors to be raised later when attempting to set attributes on the instance.

Current Behavior

#!/usr/bin/env python3
from datetime import time

# from pydantic import BaseModel
from odmantic import Model


class Test(Model):
    foo: time


t = Test(foo=time(1, 2, 3))

print(t)
t.foo = time(4, 5, 6)

print(t)

obj = t.model_dump()
print(obj)

u = Test.model_construct(**obj)
# u = Test(**obj)

print(u)

u.foo = time(0, 9, 8)  # raises AttributeError
print(u)

Expected behavior

In the above reproduction, I would expect the u instance to behave as if it'd been created a la Test(**obj).

Environment

  • ODMantic version: 1.0.2
  • MongoDB version: 4.7.2
  • Pydantic infos (output of python -c "import pydantic.utils; print(pydantic.utils.version_info())):
             pydantic version: 2.7.2
        pydantic-core version: 2.18.3
          pydantic-core build: profile=release pgo=true
                 install path: /workspaces/maven.tse.shepherd/.venv/lib/python3.12/site-packages/pydantic
               python version: 3.12.3 (main, May 17 2024, 17:50:29) [GCC 12.2.0]
                     platform: Linux-5.15.0-107-generic-x86_64-with-glibc2.36
             related packages: mypy-1.10.0 fastapi-0.111.0 typing_extensions-4.12.0
                       commit: unknown
  • Version of additional modules (if relevant):
    • ...

Additional context

Server version shouldn't play into this, as it's reproducible standalone, without talking to mongodb at all.

@nernst nernst added the bug Something isn't working label May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant