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

Create empty id field in models #23

Open
i8enn opened this issue Jul 21, 2020 · 1 comment · Fixed by #25 · May be fixed by #27
Open

Create empty id field in models #23

i8enn opened this issue Jul 21, 2020 · 1 comment · Fixed by #25 · May be fixed by #27
Assignees
Labels
bug Something isn't working

Comments

@i8enn
Copy link
Owner

i8enn commented Jul 21, 2020

I noticed that saving the models also creates an empty id in both the _doc attribute for DBPydanticMixin instance and the MongoDB collection. Also, if you call the dict() method on the model, this field will be included in the result. This is especially noticeable with nested models. But just comparing 2 models - everything will be fine.

This is not entirely good.

Mini-prof from test breakpoint
(ipdb>) debug(post, post.dict())                                                                                                                                                                                                             
<stdin>:1 <module> (no code context for debug call, code inspection impossible)
    Post(
        title='test',
        body='test_body',
        author=User(
            username='test',
            created=datetime.datetime(2020, 7, 21, 16, 16, 43, 725327),
            age=10,
            type=<UserTypesEnum.Reader: 'reader'>,
        ),
        comments=None,
        _id=ObjectId('5f16dcabbee4a5bab3584a8f'),
        _doc={
            '_id': ObjectId('5f16dcabbee4a5bab3584a8f'),
            'title': 'test',
            'body': 'test_body',
            'author': {
                'username': 'test',
                'created': datetime.datetime(2020, 7, 21, 16, 16, 43, 725327),
                'age': 10,
                'type': <UserTypesEnum.Reader: 'reader'>,
                'id': None,
            },
            'comments': None,
        },
    ) (Post)
    {
        'title': 'test',
        'body': 'test_body',
        'author': {
            'username': 'test',
            'created': datetime.datetime(2020, 7, 21, 16, 16, 43, 725327),
            'age': 10,
            'type': <UserTypesEnum.Reader: 'reader'>,
            'id': None,
        },
        'comments': None,
        'id': ObjectId('5f16dcabbee4a5bab3584a8f'),
    } (dict) len=5
(ipdb>)

Environment:

Python - 3.8
motor - 2.1.0
pymongo - 3.10.1
pydantic - 1.6.1
pydantic-odm - 0.2

@i8enn i8enn added the bug Something isn't working label Jul 21, 2020
@i8enn i8enn self-assigned this Jul 21, 2020
@i8enn i8enn added this to Issues Backlog in Development - Issues via automation Jul 21, 2020
@i8enn i8enn moved this from Issues Backlog to To Do in Development - Issues Jul 21, 2020
@i8enn i8enn moved this from To Do to In progress in Development - Issues Jul 21, 2020
i8enn added a commit that referenced this issue Jul 24, 2020
Included decoders to BasePydanticMixin
Implemented decoding MongoDB documents before update mixin model
Removed unused method, functions and properties from mixins and tests

Fix #23
@i8enn i8enn closed this as completed in #25 Jul 24, 2020
Development - Issues automation moved this from In progress to Done Jul 24, 2020
@i8enn
Copy link
Owner Author

i8enn commented Jul 24, 2020

This issue don't resolved. Need checking all methods of creating or updating models.

@i8enn i8enn reopened this Jul 24, 2020
Development - Issues automation moved this from Done to Issues Backlog Jul 24, 2020
@i8enn i8enn moved this from Issues Backlog to To Do in Development - Issues Jul 24, 2020
@tc-imba tc-imba linked a pull request Aug 19, 2020 that will close this issue
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
1 participant