Skip to content

Commit 3a9d30c

Browse files
committed
fix: avoid duplicate $project stage in union pipelines
1 parent 03b7c93 commit 3a9d30c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

django_mongodb_backend/compiler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,10 @@ def get_combinator_queries(self):
625625
fields[expr.alias] = 1
626626
else:
627627
fields[alias] = f"${ref}" if alias != ref else 1
628-
inner_pipeline.append({"$project": fields})
628+
# Avoid duplicating the same $project stage
629+
# when reusing subquery projections.
630+
if not inner_pipeline or inner_pipeline[-1] != {"$project": fields}:
631+
inner_pipeline.append({"$project": fields})
629632
# Combine query with the current combinator pipeline.
630633
if combinator_pipeline:
631634
combinator_pipeline.append(

0 commit comments

Comments
 (0)