diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 7057642f..b362016c 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -77,6 +77,7 @@ jobs: db_functions empty expressions.tests.ExpressionOperatorTests + expressions.tests.FieldTransformTests.test_transform_in_values expressions.tests.NegatedExpressionTests expressions_case defer diff --git a/django_mongodb/compiler.py b/django_mongodb/compiler.py index ebbf0a74..ea9f97dc 100644 --- a/django_mongodb/compiler.py +++ b/django_mongodb/compiler.py @@ -153,9 +153,19 @@ def get_columns(self): columns = ( self.get_default_columns(select_mask) if self.query.default_cols else self.query.select ) - return tuple((column.target.column, column) for column in columns) + tuple( - self.query.annotation_select.items() - ) + annotation_idx = 1 + result = [] + for column in columns: + if hasattr(column, "target"): + # column is a Col. + target = column.target.column + else: + # column is a Transform in values()/values_list() that needs a + # name for $proj. + target = f"__annotation{annotation_idx}" + annotation_idx += 1 + result.append((target, column)) + return tuple(result) + tuple(self.query.annotation_select.items()) def _get_ordering(self): """