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

add admin_filters tests to CI and fix bugs identified by them #170

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
- name: Run tests
run: >
python3 django_repo/tests/runtests.py --settings mongodb_settings -v 2
admin_filters
aggregation
aggregation_regress
annotations
Expand Down
10 changes: 2 additions & 8 deletions django_mongodb/aggregates.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from copy import deepcopy

from django.db.models.aggregates import Aggregate, Count, StdDev, Variance
from django.db.models.expressions import Case, Value, When
from django.db.models.lookups import IsNull
from django.db.models.sql.where import WhereNode

from .query_utils import process_lhs

Expand Down Expand Up @@ -45,12 +42,9 @@ def count(self, compiler, connection, resolve_inner_expression=False, **extra_co
node = self.copy()
node.filter = None
source_expressions = node.get_source_expressions()
filter_ = deepcopy(self.filter)
filter_.add(
WhereNode([IsNull(source_expressions[0], True)], negated=True),
filter_.default,
condition = When(
self.filter, then=Case(When(IsNull(source_expressions[0], False), then=Value(1)))
)
condition = When(filter_, then=Value(1))
node.set_source_expressions([Case(condition)] + source_expressions[1:])
inner_expression = process_lhs(node, compiler, connection)
else:
Expand Down
8 changes: 6 additions & 2 deletions django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,12 @@ def build_query(self, columns=None):
)
if not query.aggregation_pipeline:
query.aggregation_pipeline = []
query.aggregation_pipeline.append({"$group": {"_id": distinct_fields}})
query.project_fields = {key: f"$_id.{key}" for key in distinct_fields}
query.aggregation_pipeline.extend(
[
{"$group": {"_id": distinct_fields}},
{"$project": {key: f"$_id.{key}" for key in distinct_fields}},
]
)
else:
# Otherwise, project fields without grouping.
query.project_fields = self.get_project_fields(columns, ordering_fields)
Expand Down
2 changes: 1 addition & 1 deletion django_mongodb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def join(self, compiler, connection):
if isinstance(hand_side_value, Col):
# If the column is not part of the joined table, add it to
# lhs_fields.
if hand_side_value.alias != self.table_name:
if hand_side_value.alias != self.table_alias:
pos = len(lhs_fields)
lhs_fields.append(expr.lhs.as_mql(compiler, connection))
else:
Expand Down