Skip to content

Commit

Permalink
fix: projections for aggregations (#292)
Browse files Browse the repository at this point in the history
* fix: projections for aggregations
  • Loading branch information
roman-right authored Jun 24, 2022
1 parent 021bd37 commit 2be0bc1
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.9 ]
python-version: [ 3.10.5 ]
os: [ ubuntu-18.04 ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.9 ]
python-version: [ 3.10.5 ]
os: [ ubuntu-18.04 ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.10.5
- name: install poetry
uses: abatilo/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-publish-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.10.5
- name: install poetry
uses: abatilo/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9 ]
python-version: [ 3.7, 3.8, 3.9, 3.10.5 ]
poetry-version: [ 1.1.4 ]
mongodb-version: [ 4.4, 5.0 ]
pydantic-version: [1.9.0]
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
repos:
- repo: https://github.com/ambv/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
language_version: python3.9
language_version: python3.10
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion beanie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from beanie.odm.views import View
from beanie.odm.union_doc import UnionDoc

__version__ = "1.11.4"
__version__ = "1.11.5"
__all__ = [
# ODM
"Document",
Expand Down
10 changes: 5 additions & 5 deletions beanie/odm/queries/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def get_aggregation_pipeline(
match_pipeline: List[Mapping[str, Any]] = (
[{"$match": self.find_query}] if self.find_query else []
)
projection_pipeline: List[Mapping[str, Any]] = (
[{"$project": get_projection(self.projection_model)}]
if self.projection_model
else []
)
projection_pipeline: List[Mapping[str, Any]] = []
if self.projection_model:
projection = get_projection(self.projection_model)
if projection is not None:
projection_pipeline = [{"$project": projection}]
return match_pipeline + self.aggregation_pipeline + projection_pipeline

@property
Expand Down
5 changes: 4 additions & 1 deletion beanie/odm/utils/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def get_projection(
return None
if hasattr(model, "Settings"): # MyPy checks
settings = getattr(model, "Settings")
if hasattr(settings, "projection"):
if (
hasattr(settings, "projection")
and getattr(settings, "projection") is not None
):
return getattr(settings, "projection")

if getattr(model.Config, "extra", None) == "allow":
Expand Down
10 changes: 9 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Beanie project

## [1.11.5] - 2022-24-06

### Fix

- Projection fix for aggregations

## [1.11.4] - 2022-13-06

### Improvement
Expand Down Expand Up @@ -889,4 +895,6 @@ how specific type should be presented in the database

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

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

[1.11.5]: https://pypi.org/project/beanie/1.11.5
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "beanie"
version = "1.11.4"
version = "1.11.5"
description = "Asynchronous Python ODM for MongoDB"
authors = ["Roman <[email protected]>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_beanie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "1.11.4"
assert __version__ == "1.11.5"

0 comments on commit 2be0bc1

Please sign in to comment.