mongox: Possible error in the return of the update method
I have been creating the update_or_create method based on the get_or_create and update methods, doing some tests I found a possible bug in the update method.
in the database I have the following data.
[
{
"name": "Venom",
"year": 2023
},{
"name": "Venom2",
"year": 2021
}
]
and when executing the next query Movie.query({Movie.name: "Venom"}).update({Movie.year: 2021})
, what I would expect is for the method to return
[
{
"name": "Venom",
"year": 2021
}
]
But what it returns is
[
{
"name": "Venom",
"year": 2021
},{
"name": "Venom2",
"year": 2021
}
]
Is this a bug or is expected to happen?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- :bug: new update, bug #27 fixed — committed to MAD-py/mongox by MAD-py 2 years ago
Yeah perfect. Thanks
Issue resolved #29
Great, Thank you @MAD-py
I get your point now. Maybe we need to fix that in a separate PR? Probably we can fix update in a PR when we add test in the update case as you explained. I see the current test we have for update is not testing that https://github.com/aminalaee/mongox/blob/e6698f62be29b00dc372884a82f7f0b07078f1ea/tests/test_models.py#L252-L259
but it would be more like this
and if we want to update more fields it would be
if what we want is to be able to pass field to field it would be
but for this we must use is **kwargs
Of course, today is difficult for me, but I will take a look at it in the next few days.
I agree this is not expected, I think this is a bug. Will you be able to take a look?