Opened 4 months ago

Last modified 4 months ago

#35614 closed Bug

SQLCompiler.as_subquery_condition shouldn't modify the query object — at Initial Version

Reported by: Csirmaz Bendegúz Owned by: Csirmaz Bendegúz
Component: Database layer (models, ORM) Version: 5.0
Severity: Normal Keywords:
Cc: Csirmaz Bendegúz Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

SQLCompiler.as_subquery_condition modifies the query object.

django/db/models/sql/compiler.py#L1619

self.query.where.add(RawSQL("%s = %s" % (lhs_sql, rhs), lhs_params), AND)

This is unfortunate, because whenever the query is re-compiled, it will add another condition.
I noticed the issue when inspecting .query on a queryset. Each time I accessed .query, a new condition appeared.
An example queryset can be found in test MultiColumnFKTests.test_double_nested_query.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top