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

Engine not saving the model if it contains an Optional EmbeddedModel set to None #272

Open
M4rk3tt0 opened this issue Oct 8, 2022 · 4 comments · May be fixed by #273
Open

Engine not saving the model if it contains an Optional EmbeddedModel set to None #272

M4rk3tt0 opened this issue Oct 8, 2022 · 4 comments · May be fixed by #273
Labels
bug Something isn't working

Comments

@M4rk3tt0
Copy link

M4rk3tt0 commented Oct 8, 2022

Bug

I have an Optional EmbeddedModel inside my main model. If I don't set a value for it, when the engine tries to save the data in the database, I get the error: TypeError: 'NoneType' object is not iterable

Current Behavior

This is a basic example that shows this behavior (it's the same with the AIOEngine):

from odmantic import Model, EmbeddedModel, SyncEngine

class Profile(EmbeddedModel):
    name: str
    age: int

class User(Model):
    username: str
    password: str
    profile: Profile | None

engine = SyncEngine()

user = User(username="John", password="password")
engine.save(user)

Expected behavior

The engine should save the model even if the EmbeddedModel is initially not set.

Environment

  • ODMantic version: 0.9.0
  • MongoDB version: 6.0.1
  • Pydantic infos (output of python -c "import pydantic.utils; print(pydantic.utils.version_info())):
             pydantic version: 1.10.2
            pydantic compiled: True
                 install path: D:\Projects\Python\odmantic-test\.venv\Lib\site-packages\pydantic
               python version: 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
                     platform: Windows-10-10.0.19043-SP0
     optional deps. installed: ['typing-extensions']
@M4rk3tt0 M4rk3tt0 added the bug Something isn't working label Oct 8, 2022
@art049
Copy link
Owner

art049 commented Oct 9, 2022

Hello, thanks for the bug report.

I'll fix this asap.

@art049 art049 linked a pull request Oct 10, 2022 that will close this issue
@paulovitorweb
Copy link

Hello. Thanks for the library.

Any predictions on when this will be merged?

@Creadeyh
Copy link

Hello, this is still an issue in odmantic 0.9.2

@tejastee
Copy link

tejastee commented Nov 3, 2024

Seeing same bug in 1.0.2 odmantic

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

Successfully merging a pull request may close this issue.

5 participants