Skip to content

Commit

Permalink
Fix broken references in subqueries and joins
Browse files Browse the repository at this point in the history
  • Loading branch information
WaVEV committed Dec 31, 2024
1 parent 3beb72f commit adc286a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
8 changes: 4 additions & 4 deletions django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,14 @@ def project_field(column):
*self.annotations.items(),
]
else:
for _, expression in self.query.selected.items():
for expression in self.query.selected.values():
# Reference to an annotation.
if isinstance(expression, str):
expression = self.annotations[expression]
alias, expression = expression, self.annotations[expression]
# Reference to a column.
elif isinstance(expression, int):
expression = columns[expression]
selected.append(project_field(expression))
alias, expression = project_field(columns[expression])
selected.append((alias, expression))

# Populate QuerySet.select_related() data.
related_columns = []
Expand Down
6 changes: 5 additions & 1 deletion django_mongodb/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ def ref(self, compiler, connection): # noqa: ARG001
if isinstance(self.source, Col) and self.source.alias != compiler.collection_name
else ""
)
return f"${prefix}{self.refs}"
if hasattr(self, "ordinal"):
refs, _ = compiler.columns[self.ordinal - 1]
else:
refs = self.refs
return f"${prefix}{refs}"


def star(self, compiler, connection): # noqa: ARG001
Expand Down
18 changes: 4 additions & 14 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"auth_tests.test_views.LoginTest.test_login_session_without_hash_session_key",
# GenericRelation.value_to_string() assumes integer pk.
"contenttypes_tests.test_fields.GenericRelationTests.test_value_to_string",
# Broken by https://github.com/django/django/commit/65ad4ade74dc9208b9d686a451cd6045df0c9c3a
"aggregation.tests.AggregateTestCase.test_even_more_aggregate",
"aggregation.tests.AggregateTestCase.test_grouped_annotation_in_group_by",
"aggregation.tests.AggregateTestCase.test_non_grouped_annotation_not_in_group_by",
"aggregation_regress.tests.AggregationTests.test_aggregate_fexpr",
"aggregation_regress.tests.AggregationTests.test_values_list_annotation_args_ordering",
"annotations.tests.NonAggregateAnnotationTestCase.test_annotation_subquery_and_aggregate_values_chaining",
"annotations.tests.NonAggregateAnnotationTestCase.test_values_fields_annotations_order",
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_and_datetime_annotations",
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_list_and_datetime_annotations",
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_list_and_annotations",
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_field_and_annotation_values",
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_two_annotated_values_list",
"queries.tests.Queries1Tests.test_union_values_subquery",
# pymongo.errors.WriteError: Performing an update on the path '_id'
# would modify the immutable field '_id'
"migrations.test_operations.OperationTests.test_composite_pk_operations",
Expand Down Expand Up @@ -216,9 +202,13 @@ def django_test_expected_failures(self):
"prefetch_related.tests.Ticket21410Tests",
"queryset_pickle.tests.PickleabilityTestCase.test_pickle_prefetch_related_with_m2m_and_objects_deletion",
"serializers.test_json.JsonSerializerTestCase.test_serialize_prefetch_related_m2m",
"serializers.test_json.JsonSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
"serializers.test_jsonl.JsonlSerializerTestCase.test_serialize_prefetch_related_m2m",
"serializers.test_jsonl.JsonlSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
"serializers.test_xml.XmlSerializerTestCase.test_serialize_prefetch_related_m2m",
"serializers.test_xml.XmlSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
"serializers.test_yaml.YamlSerializerTestCase.test_serialize_prefetch_related_m2m",
"serializers.test_yaml.YamlSerializerTestCase.test_serialize_prefetch_related_m2m_with_natural_keys",
},
"AutoField not supported.": {
"bulk_create.tests.BulkCreateTests.test_bulk_insert_nullable_fields",
Expand Down

0 comments on commit adc286a

Please sign in to comment.