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

Fixed #30854 -- Fixed QuerySet.select_related() with multiple FilteredRelations.

This commit is contained in:
Hasan Ramezani
2019-10-10 21:13:21 +02:00
committed by Mariusz Felisiak
parent e1ae2b0050
commit 6a75cea76a
2 changed files with 17 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import collections
import re
from functools import partial
from itertools import chain
from django.core.exceptions import EmptyResultSet, FieldError
@@ -896,6 +897,9 @@ class SQLCompiler:
if from_obj:
f.remote_field.set_cached_value(from_obj, obj)
def remote_setter(name, obj, from_obj):
setattr(from_obj, name, obj)
for name in list(requested):
# Filtered relations work only on the topmost level.
if cur_depth > 1:
@@ -906,15 +910,12 @@ class SQLCompiler:
model = join_opts.model
alias = joins[-1]
from_parent = issubclass(model, opts.model) and model is not opts.model
def remote_setter(obj, from_obj):
setattr(from_obj, name, obj)
klass_info = {
'model': model,
'field': f,
'reverse': True,
'local_setter': local_setter,
'remote_setter': remote_setter,
'remote_setter': partial(remote_setter, name),
'from_parent': from_parent,
}
related_klass_infos.append(klass_info)