summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <simon.charette@zapier.com>2019-09-23 15:51:43 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-09-24 09:47:21 +0200
commit6b7bd079a6fc4e84553262b65074dbe0af456b03 (patch)
treedfff4f1b709b7f97786ecab8b5b5b867f83a221a /django
parent9510af35fce9de740f76f04cb5216c42daa1b9f3 (diff)
[3.0.x] Fixed #30796 -- Prevented select_related() from mutating a queryset on chaining.
Thanks Darren Maki for the report. Backport of 37f8f293775d0b672da8ae369d9a4e17f1db7851 from master
Diffstat (limited to 'django')
-rw-r--r--django/db/models/sql/query.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 8e55bd092d..ea51912e8b 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -6,6 +6,7 @@ themselves do not have to (and could be backed by things other than SQL
databases). The abstraction barrier only works one way: this module has to know
all about the internals of models in order to get the information it needs.
"""
+import copy
import difflib
import functools
import inspect
@@ -324,6 +325,10 @@ class Query(BaseExpression):
obj._extra_select_cache = None
else:
obj._extra_select_cache = self._extra_select_cache.copy()
+ if self.select_related is not False:
+ # Use deepcopy because select_related stores fields in nested
+ # dicts.
+ obj.select_related = copy.deepcopy(obj.select_related)
if 'subq_aliases' in self.__dict__:
obj.subq_aliases = self.subq_aliases.copy()
obj.used_aliases = self.used_aliases.copy()