Skip to content

Commit c43a1df

Browse files
committed
fix errors in tests.
1 parent d068e06 commit c43a1df

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

django_mongodb/compiler.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def pre_sql_setup(self, with_col_aliases=False):
6565
all_replacements.update(replacements)
6666
group_expressions |= set(expr.get_group_by_cols())
6767
self.annotations[target] = result_expr
68-
if group:
68+
if group or self.query.group_by:
6969
order_by = self.get_order_by()
7070
for expr, (_, _, is_ref) in order_by:
7171
# Skip references to the SELECT clause, as all expressions in
@@ -81,8 +81,7 @@ def pre_sql_setup(self, with_col_aliases=False):
8181
group_expressions.add(expr)
8282
if isinstance(self.query.group_by, tuple | list):
8383
group_expressions |= set(self.query.group_by)
84-
85-
if self.query.group_by is None:
84+
elif self.query.group_by is None:
8685
group_expressions = set()
8786

8887
all_strings = "".join(
@@ -170,9 +169,6 @@ def execute_sql(
170169
):
171170
# QuerySet.count()
172171
self.pre_sql_setup()
173-
if self.query.annotations == {"__count": Count("*")}:
174-
return [self.get_count()]
175-
176172
columns = self.get_columns()
177173
try:
178174
query = self.build_query(

django_mongodb/features.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ def django_test_expected_failures(self):
397397
"lookup.tests.LookupQueryingTests.test_filter_subquery_lhs",
398398
"model_fields.test_jsonfield.TestQuerying.test_nested_key_transform_on_subquery",
399399
"model_fields.test_jsonfield.TestQuerying.test_obj_subquery_lookup",
400+
"aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_aggregate_ref_subquery_annotation",
400401
},
401402
"Using a QuerySet in annotate() is not supported on MongoDB.": {
402403
"annotations.tests.NonAggregateAnnotationTestCase.test_annotation_and_alias_filter_in_subquery",
@@ -434,6 +435,7 @@ def django_test_expected_failures(self):
434435
"queries.tests.ValuesSubqueryTests.test_values_in_subquery",
435436
"queries.tests.WeirdQuerysetSlicingTests.test_empty_sliced_subquery",
436437
"queries.tests.WeirdQuerysetSlicingTests.test_empty_sliced_subquery_exclude",
438+
"aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_reused_subquery",
437439
},
438440
# Invalid $project :: caused by :: Unknown expression $count
439441
# https://github.com/mongodb-labs/django-mongodb/issues/79
@@ -504,6 +506,7 @@ def django_test_expected_failures(self):
504506
"queries.tests.Queries1Tests.test_tickets_6180_6203",
505507
"queries.tests.Queries6Tests.test_distinct_ordered_sliced_subquery_aggregation",
506508
"update.tests.AdvancedTests.test_update_all",
509+
"aggregation.tests.AggregateTestCase.test_sum_distinct_aggregate",
507510
},
508511
"QuerySet.extra() is not supported.": {
509512
"annotations.tests.NonAggregateAnnotationTestCase.test_column_field_ordering",
@@ -535,6 +538,7 @@ def django_test_expected_failures(self):
535538
"update.tests.AdvancedTests.test_update_annotated_multi_table_queryset",
536539
},
537540
"Test inspects query for SQL": {
541+
"aggregation.tests.AggregateTestCase.test_count_star",
538542
"delete.tests.DeletionTests.test_only_referenced_fields_selected",
539543
"lookup.tests.LookupTests.test_in_ignore_none",
540544
"lookup.tests.LookupTests.test_textfield_exact_null",

django_mongodb/functions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
Upper,
3636
)
3737
from django.db.models.lookups import Exact
38-
from django.db.models.query_utils import Q
38+
from django.db.models.sql.where import WhereNode
3939

4040
from .query_utils import process_lhs
4141

@@ -86,7 +86,7 @@ def aggregate(self, compiler, connection, **extra_context): # noqa: ARG001
8686
node = self
8787
lhs_mql = process_lhs(node, compiler, connection)
8888
operator = MONGO_AGGREGATION.get(self.__class__)
89-
if self.__class__ in (StdDev, Variance) and "_SAMP" in self.functions:
89+
if self.__class__ in (StdDev, Variance) and "_SAMP" in self.function:
9090
operator = operator.replace("Pop", "Samp")
9191
return {f"${operator}": lhs_mql}
9292

@@ -128,7 +128,10 @@ def count(self, compiler, connection, **extra_context):
128128
copy.filter = None
129129
source_expressions = copy.get_source_expressions()
130130
filter_ = deepcopy(self.filter)
131-
filter_.add(~Q(Exact(source_expressions[0], Value(None))), filter_.default)
131+
filter_.add(
132+
WhereNode([Exact(source_expressions[0], Value(None))], negated=True),
133+
filter_.default,
134+
)
132135
condition = When(filter_, then=Value(1))
133136
copy.set_source_expressions([Case(condition)] + source_expressions[1:])
134137
node = copy

django_mongodb/operations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,17 @@ def get_db_converters(self, expression):
8282
elif internal_type == "DateTimeField":
8383
if settings.USE_TZ:
8484
converters.append(self.convert_datetimefield_value)
85-
elif internal_type == "DecimalField":
85+
elif internal_type in ("DecimalField", "FloatField") or internal_type.endswith(
86+
"IntegerField"
87+
):
8688
converters.append(self.convert_decimalfield_value)
8789
elif internal_type == "JSONField":
8890
converters.append(self.convert_jsonfield_value)
8991
elif internal_type == "TimeField":
9092
converters.append(self.convert_timefield_value)
9193
elif internal_type == "UUIDField":
9294
converters.append(self.convert_uuidfield_value)
95+
9396
return converters
9497

9598
def convert_datefield_value(self, value, expression, connection):

0 commit comments

Comments
 (0)