summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorNicolas Delaby <nicolas.delaby@infarm.com>2024-01-23 11:51:24 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-01-29 20:29:49 +0100
commit820c5f1bacd41713bd30d8b5fefb66752ff15c4c (patch)
treed5182900a739e598b967523537902ddca7035654 /django/db/models/sql/query.py
parenta5365339eaee043895a79dbbdd7462f1399136e5 (diff)
Fixed #35135 -- Made FilteredRelation raise ValueError on querysets as rhs.
Regression in 59f475470494ce5b8cbff816b1e5dafcbd10a3a3.
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(