odmantic
odmantic copied to clipboard
Engine not saving the model if it contains an Optional EmbeddedModel set to None
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']
Hello, thanks for the bug report.
I'll fix this asap.
Hello. Thanks for the library.
Any predictions on when this will be merged?
Hello, this is still an issue in odmantic 0.9.2