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

Problem with list of EmbeddedModel whose fields use key_name #263

Closed
iXB3 opened this issue Sep 9, 2022 · 1 comment · Fixed by #269
Closed

Problem with list of EmbeddedModel whose fields use key_name #263

iXB3 opened this issue Sep 9, 2022 · 1 comment · Fixed by #269
Labels
bug Something isn't working

Comments

@iXB3
Copy link
Contributor

iXB3 commented Sep 9, 2022

I found problems with list of embedded model whose fields use key_name: the embedded list of document saved in db does not use key_name (following a code to reproduce the issue)

import odmantic as odm
import typing as tp
 
class ListEl(odm.EmbeddedModel):
    a: int = odm.Field(key_name='in-a')

class Out(odm.Model):
    o: tp.Optional[str] = odm.Field(key_name='out-o')
    inner: tp.List[ListEl] = odm.Field(key_name='in')

out = Out(inner=[ListEl(a=3), ListEl(a=4)], o='ciao')
engine = odm.SyncEngine()
engine.save(out)
# document saved: {"_id" : ObjectId(...), "in" : [{"a" : 3},{"a" : 4}],"out-o" : "ciao"}

The document should be {"_id" : ObjectId(...), "in" : [{"in-a" : 3},{"in-a" : 4}],"out-o" : "ciao"}

Probably once resolved the insertion, there will be a problem similar to #260 in resuming document from db (I'm testing my code on an already populated db and the problem arises).

Environment

  • ODMantic version: 0.8.0
  • MongoDB version: 5.0.3
  • Pydantic infos (output of python -c "import pydantic.utils; print(pydantic.utils.version_info())):
    pydantic version: 1.10.1
    pydantic compiled: True
    install path: C:\Users\utente\Ploovium\Repos\Ploovium-UtilsNEW\venv\Lib\site-packages\pydantic
    python version: 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
    platform: Windows-10-10.0.19043-SP0
    optional deps. installed: ['typing-extensions']
@iXB3 iXB3 added the bug Something isn't working label Sep 9, 2022
@art049
Copy link
Owner

art049 commented Sep 24, 2022

Thanks for reporting I just tested the behavior, you're totally right!
Incoming fix 🔨🚀

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.

2 participants