Skip to content

Commit adc286a

Browse files
committed
Fix broken references in subqueries and joins
1 parent 3beb72f commit adc286a

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

django_mongodb/compiler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,14 @@ def project_field(column):
428428
*self.annotations.items(),
429429
]
430430
else:
431-
for _, expression in self.query.selected.items():
431+
for expression in self.query.selected.values():
432432
# Reference to an annotation.
433433
if isinstance(expression, str):
434-
expression = self.annotations[expression]
434+
alias, expression = expression, self.annotations[expression]
435435
# Reference to a column.
436436
elif isinstance(expression, int):
437-
expression = columns[expression]
438-
selected.append(project_field(expression))
437+
alias, expression = project_field(columns[expression])
438+
selected.append((alias, expression))
439439

440440
# Populate QuerySet.select_related() data.
441441
related_columns = []

django_mongodb/expressions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ def ref(self, compiler, connection): # noqa: ARG001
178178
if isinstance(self.source, Col) and self.source.alias != compiler.collection_name
179179
else ""
180180
)
181-
return f"${prefix}{self.refs}"
181+
if hasattr(self, "ordinal"):
182+
refs, _ = compiler.columns[self.ordinal - 1]
183+
else:
184+
refs = self.refs
185+
return f"${prefix}{refs}"
182186

183187

184188
def star(self, compiler, connection): # noqa: ARG001

django_mongodb/features.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
8888
"auth_tests.test_views.LoginTest.test_login_session_without_hash_session_key",
8989
# GenericRelation.value_to_string() assumes integer pk.
9090
"contenttypes_tests.test_fields.GenericRelationTests.test_value_to_string",
91-
# Broken by https://github.com/django/django/commit/65ad4ade74dc9208b9d686a451cd6045df0c9c3a
92-
"aggregation.tests.AggregateTestCase.test_even_more_aggregate",
93-
"aggregation.tests.AggregateTestCase.test_grouped_annotation_in_group_by",
94-
"aggregation.tests.AggregateTestCase.test_non_grouped_annotation_not_in_group_by",
95-
"aggregation_regress.tests.AggregationTests.test_aggregate_fexpr",
96-
"aggregation_regress.tests.AggregationTests.test_values_list_annotation_args_ordering",
97-
"annotations.tests.NonAggregateAnnotationTestCase.test_annotation_subquery_and_aggregate_values_chaining",
98-
"annotations.tests.NonAggregateAnnotationTestCase.test_values_fields_annotations_order",
99-
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_and_datetime_annotations",
100-
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_list_and_datetime_annotations",
101-
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_list_and_annotations",
102-
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_field_and_annotation_values",
103-
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_two_annotated_values_list",
104-
"queries.tests.Queries1Tests.test_union_values_subquery",
10591
# pymongo.errors.WriteError: Performing an update on the path '_id'
10692
# would modify the immutable field '_id'
10793
"migrations.test_operations.OperationTests.test_composite_pk_operations",
@@ -216,9 +202,13 @@ def django_test_expected_failures(self):
216202
"prefetch_related.tests.Ticket21410Tests",
217203
"queryset_pickle.tests.PickleabilityTestCase.test_pickle_prefetch_related_with_m2m_and_objects_deletion",
218204
"serializers.test_json.JsonSerializerTestCase.test_serialize_prefetch_related_m2m",
205+
"serializers.test_json.JsonSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
219206
"serializers.test_jsonl.JsonlSerializerTestCase.test_serialize_prefetch_related_m2m",
207+
"serializers.test_jsonl.JsonlSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
220208
"serializers.test_xml.XmlSerializerTestCase.test_serialize_prefetch_related_m2m",
209+
"serializers.test_xml.XmlSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
221210
"serializers.test_yaml.YamlSerializerTestCase.test_serialize_prefetch_related_m2m",
211+
"serializers.test_yaml.YamlSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
222212
},
223213
"AutoField not supported.": {
224214
"bulk_create.tests.BulkCreateTests.test_bulk_insert_nullable_fields",

0 commit comments

Comments
 (0)