1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +00:00

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.
This commit is contained in:
Aymeric Augustin
2014-05-10 16:39:20 +02:00
parent fb90b7cda2
commit f574220f09
2 changed files with 13 additions and 0 deletions

View File

@@ -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]