Skip to content

Commit 3f85f34

Browse files
timgrahamWaVEV
authored andcommitted
cosmetic edits + remove unused code
1 parent 85d2b0d commit 3f85f34

File tree

5 files changed

+8
-38
lines changed

5 files changed

+8
-38
lines changed

django_mongodb/compiler.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ def results_iter(
261261
rows = map(tuple, rows)
262262
return rows
263263

264-
def has_results(self):
265-
return bool(self.execute_sql(SINGLE))
266-
267264
def _make_result(self, entity, columns):
268265
"""
269266
Decode values for the given fields from the database entity.

django_mongodb/features.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
4848
"expressions.tests.NegatedExpressionTests.test_filter",
4949
"expressions_case.tests.CaseExpressionTests.test_order_by_conditional_implicit",
5050
# NotSupportedError: order_by() expression not supported.
51-
# Lookup in order_by() not supported:
52-
# argument of type '<database function>' is not iterable
5351
"aggregation.tests.AggregateTestCase.test_aggregation_order_by_not_selected_annotation_values",
5452
"db_functions.comparison.test_coalesce.CoalesceTests.test_ordering",
5553
"db_functions.tests.FunctionTests.test_nested_function_ordering",
@@ -345,6 +343,7 @@ def django_test_expected_failures(self):
345343
"aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_aggregate_ref_subquery_annotation",
346344
},
347345
"Using a QuerySet in annotate() is not supported on MongoDB.": {
346+
"aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_reused_subquery",
348347
"aggregation.tests.AggregateTestCase.test_filter_in_subquery_or_aggregation",
349348
"aggregation.tests.AggregateTestCase.test_group_by_subquery_annotation",
350349
"aggregation.tests.AggregateTestCase.test_group_by_reference_subquery",
@@ -384,7 +383,6 @@ def django_test_expected_failures(self):
384383
"queries.tests.ValuesSubqueryTests.test_values_in_subquery",
385384
"queries.tests.WeirdQuerysetSlicingTests.test_empty_sliced_subquery",
386385
"queries.tests.WeirdQuerysetSlicingTests.test_empty_sliced_subquery_exclude",
387-
"aggregation.test_filter_argument.FilteredAggregateTests.test_filtered_reused_subquery",
388386
},
389387
"Cannot use QuerySet.delete() when querying across multiple collections on MongoDB.": {
390388
"delete.tests.FastDeleteTests.test_fast_delete_aggregation",
@@ -420,6 +418,7 @@ def django_test_expected_failures(self):
420418
"timezones.tests.NewDatabaseTests.test_query_datetimes_in_other_timezone",
421419
},
422420
"QuerySet.distinct() is not supported.": {
421+
"aggregation.tests.AggregateTestCase.test_sum_distinct_aggregate",
423422
"lookup.tests.LookupTests.test_lookup_collision_distinct",
424423
"queries.tests.ExcludeTest17600.test_exclude_plain_distinct",
425424
"queries.tests.ExcludeTest17600.test_exclude_with_q_is_equal_to_plain_exclude",
@@ -437,7 +436,6 @@ def django_test_expected_failures(self):
437436
"queries.tests.Queries1Tests.test_tickets_6180_6203",
438437
"queries.tests.Queries6Tests.test_distinct_ordered_sliced_subquery_aggregation",
439438
"update.tests.AdvancedTests.test_update_all",
440-
"aggregation.tests.AggregateTestCase.test_sum_distinct_aggregate",
441439
},
442440
"QuerySet.extra() is not supported.": {
443441
"annotations.tests.NonAggregateAnnotationTestCase.test_column_field_ordering",

django_mongodb/functions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
from .query_utils import process_lhs
4141

42-
MONGO_AGGREGATION = {
42+
MONGO_AGGREGATIONS = {
4343
Avg: "avg",
4444
Count: "sum",
4545
Max: "max",
@@ -48,8 +48,6 @@
4848
Sum: "sum",
4949
Variance: "stdDevPop",
5050
}
51-
52-
5351
MONGO_OPERATORS = {
5452
Ceil: "ceil",
5553
Coalesce: "ifNull",
@@ -85,7 +83,7 @@ def aggregate(self, compiler, connection, **extra_context): # noqa: ARG001
8583
else:
8684
node = self
8785
lhs_mql = process_lhs(node, compiler, connection)
88-
operator = MONGO_AGGREGATION.get(self.__class__)
86+
operator = MONGO_AGGREGATIONS.get(self.__class__)
8987
if self.__class__ in (StdDev, Variance) and "_SAMP" in self.function:
9088
operator = operator.replace("Pop", "Samp")
9189
return {f"${operator}": lhs_mql}

django_mongodb/operations.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def get_db_converters(self, expression):
9494
converters.append(self.convert_timefield_value)
9595
elif internal_type == "UUIDField":
9696
converters.append(self.convert_uuidfield_value)
97-
9897
return converters
9998

10099
def convert_datefield_value(self, value, expression, connection):
@@ -133,7 +132,6 @@ def convert_floatfield_value(self, value, expression, connection):
133132
return value
134133
if isinstance(value, Decimal128):
135134
return float(value.to_decimal())
136-
137135
return float(value)
138136

139137
def convert_integerfield_value(self, value, expression, connection):

django_mongodb/query.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ def __init__(self, compiler):
5656
def __repr__(self):
5757
return f"<MongoQuery: {self.mongo_query!r} ORDER {self.ordering!r}>"
5858

59-
@wrap_database_errors
60-
def count(self, limit=None, skip=None):
61-
"""
62-
Return the number of objects that would be returned, if this query was
63-
executed, up to `limit`, skipping `skip`.
64-
"""
65-
result = list(self.get_cursor(count=True, limit=limit, skip=skip))
66-
return result[0]["__count"] if result else 0
67-
6859
def order_by(self, ordering):
6960
"""
7061
Reorder query results or execution order. Called by compiler during
@@ -90,23 +81,18 @@ def delete(self):
9081
return self.collection.delete_many(self.mongo_query, **options).deleted_count
9182

9283
@wrap_database_errors
93-
def get_cursor(self, count=False, limit=None, skip=None):
84+
def get_cursor(self):
9485
"""
9586
Return a pymongo CommandCursor that can be iterated on to give the
9687
results of the query.
97-
98-
If `count` is True, return a single document with the number of
99-
documents that match the query.
100-
101-
Use `limit` or `skip` to override those options of the query.
10288
"""
10389
if self.query.low_mark == self.query.high_mark:
10490
return []
10591

10692
pipeline = self.get_pipeline()
10793
return self.collection.aggregate(pipeline)
10894

109-
def get_pipeline(self, count=False, limit=None, skip=None):
95+
def get_pipeline(self):
11096
pipeline = [] if self.subquery is None else self.subquery.get_pipeline()
11197
if self.lookup_pipeline:
11298
pipeline.extend(self.lookup_pipeline)
@@ -118,17 +104,10 @@ def get_pipeline(self, count=False, limit=None, skip=None):
118104
pipeline.append({"$project": self.project_fields})
119105
if self.ordering:
120106
pipeline.append({"$sort": dict(self.ordering)})
121-
122-
if skip is not None:
123-
pipeline.append({"$skip": skip})
124-
elif self.query.low_mark > 0:
107+
if self.query.low_mark > 0:
125108
pipeline.append({"$skip": self.query.low_mark})
126-
127-
if limit is not None:
128-
pipeline.append({"$limit": limit})
129-
elif self.query.high_mark is not None:
109+
if self.query.high_mark is not None:
130110
pipeline.append({"$limit": self.query.high_mark - self.query.low_mark})
131-
132111
return pipeline
133112

134113

0 commit comments

Comments
 (0)