#35099: Combining QuerySets with "|" or "&" mutates right-hand side.
-------------------------------------+-------------------------------------
Reporter: Alan | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* stage: Unreviewed => Accepted
Comment:
Thanks for the report.This is caused by
[https://github.com/django/django/blob/9b02ad91ead3db75036be981bab2083aebc993a6/django/db/models/sql/query.py#L688
bumping prefixes], we should probably clone `rhs` before doing this, e.g.
{{{#!diff
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index a79d66eb21..5539f35b1c 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -685,6 +685,7 @@ class Query(BaseExpression):
# except if the alias is the base table since it must be present
in the
# query on both sides.
initial_alias = self.get_initial_alias()
+ rhs = rhs.clone()
rhs.bump_prefix(self, exclude={initial_alias})
# Work out how to relabel the rhs aliases, if necessary.
}}}
Does it work for you? Would you like to prepare a patch? (a regression
test is required).
--
Ticket URL: <https://code.djangoproject.com/ticket/35099#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018cf28767ae-e23ab235-aafa-4716-92ff-2636d1d193fa-000000%40eu-central-1.amazonses.com.