Skip to content

Commit

Permalink
refactor: simplify UpdateMany and UpdateOne __await__ method (#687)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman <roman-right@protonmail.com>
  • Loading branch information
cikay and roman-right committed Sep 14, 2023
1 parent 6274f08 commit 3b9c616
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion beanie/__init__.py
Expand Up @@ -31,7 +31,7 @@
from beanie.odm.views import View
from beanie.odm.union_doc import UnionDoc

__version__ = "1.22.2"
__version__ = "1.22.3"
__all__ = [
# ODM
"Document",
Expand Down
58 changes: 29 additions & 29 deletions beanie/odm/queries/update.py
Expand Up @@ -204,17 +204,17 @@ def __await__(
update_result = yield from self._update().__await__()
if self.upsert_insert_doc is None:
return update_result
else:
if update_result is not None and update_result.matched_count == 0:
return (
yield from self.document_model.insert_one(
document=self.upsert_insert_doc,
session=self.session,
bulk_writer=self.bulk_writer,
).__await__()
)
else:
return update_result

if update_result is not None and update_result.matched_count == 0:
return (
yield from self.document_model.insert_one(
document=self.upsert_insert_doc,
session=self.session,
bulk_writer=self.bulk_writer,
).__await__()
)

return update_result


class UpdateOne(UpdateQuery):
Expand Down Expand Up @@ -352,21 +352,21 @@ def __await__(
update_result = yield from self._update().__await__()
if self.upsert_insert_doc is None:
return update_result
else:
if (
self.response_type == UpdateResponse.UPDATE_RESULT
and update_result is not None
and update_result.matched_count == 0
) or (
self.response_type != UpdateResponse.UPDATE_RESULT
and update_result is None
):
return (
yield from self.document_model.insert_one(
document=self.upsert_insert_doc,
session=self.session,
bulk_writer=self.bulk_writer,
).__await__()
)
else:
return update_result

if (
self.response_type == UpdateResponse.UPDATE_RESULT
and update_result is not None
and update_result.matched_count == 0
) or (
self.response_type != UpdateResponse.UPDATE_RESULT
and update_result is None
):
return (
yield from self.document_model.insert_one(
document=self.upsert_insert_doc,
session=self.session,
bulk_writer=self.bulk_writer,
).__await__()
)

return update_result
8 changes: 8 additions & 0 deletions docs/changelog.md
Expand Up @@ -2,6 +2,14 @@

Beanie project

## [1.22.3] - 2023-09-13
### Refactor: Simplify UpdateMany And UpdateOne __await__ Method
- Author - [Muzaffer Cikay](https://github.com/cikay)
- PR <https://github.com/roman-right/beanie/pull/687>

[1.22.3]: https://pypi.org/project/beanie/1.22.3

## [1.22.2] - 2023-09-13
### Fix get_field_type & Generalize extract_id_class
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"

[project]
name = "beanie"
version = "1.22.2"
version = "1.22.3"
description = "Asynchronous Python ODM for MongoDB"
readme = "README.md"
requires-python = ">=3.7,<4.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_beanie.py
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "1.22.2"
assert __version__ == "1.22.3"

0 comments on commit 3b9c616

Please sign in to comment.