summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 6e8813b5e7..5100869b34 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -91,6 +91,8 @@ def get_children_from_q(q):
def get_child_with_renamed_prefix(prefix, replacement, child):
+ from django.db.models.query import QuerySet
+
if isinstance(child, Node):
return rename_prefix_from_q(prefix, replacement, child)
if isinstance(child, tuple):
@@ -105,6 +107,14 @@ def get_child_with_renamed_prefix(prefix, replacement, child):
child = child.copy()
if child.name.startswith(prefix + LOOKUP_SEP):
child.name = child.name.replace(prefix, replacement, 1)
+ elif isinstance(child, QuerySet):
+ # QuerySet may contain OuterRef() references which cannot work properly
+ # without repointing to the filtered annotation and will spawn a
+ # different JOIN. Always raise ValueError instead of providing partial
+ # support in other cases.
+ raise ValueError(
+ "Passing a QuerySet within a FilteredRelation is not supported."
+ )
elif hasattr(child, "resolve_expression"):
child = child.copy()
child.set_source_expressions(