summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-05-10 16:39:20 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-05-10 17:03:42 +0200
commite9d0ef19bc87aafd71d513cd927db2655267809b (patch)
tree8b9c5c76acd2c655409c86f349be1828279296d4 /django
parentc54fb3d922fdcd00c4e17676fe4cdaa3a3f6f6d8 (diff)
[1.7.x] Fixed #22508 -- Avoided overwriting select_related.
Previously, known related objects overwrote related objects loaded though select_related. This could cancel the effect of select_related when it was used over more than one level. Thanks boxm for the bug report and timo for bisecting the regression. Backport of f574220f from master
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 043eac908b..abe882eaeb 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -291,6 +291,9 @@ class QuerySet(object):
# Add the known related objects to the model, if there are any
if self._known_related_objects:
for field, rel_objs in self._known_related_objects.items():
+ # Avoid overwriting objects loaded e.g. by select_related
+ if hasattr(obj, field.get_cache_name()):
+ continue
pk = getattr(obj, field.get_attname())
try:
rel_obj = rel_objs[pk]