Skip to content

Commit 922b203

Browse files
committed
Raise exception when subqueries are across different databases.
1 parent b4a7633 commit 922b203

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

django_mongodb/query_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def process_lhs(node, compiler, connection):
2727

2828
def process_rhs(node, compiler, connection):
2929
rhs = node.rhs
30+
db_rhs = getattr(rhs, "_db", None)
31+
if db_rhs is not None and db_rhs != connection.alias:
32+
raise ValueError(
33+
"Subqueries aren't allowed across different databases. Force "
34+
"the inner query to be evaluated using `list(inner_query)`."
35+
)
3036
if hasattr(rhs, "as_mql"):
3137
if getattr(rhs, "subquery", False):
3238
value = rhs.as_mql(compiler, connection, lookup_name=node.lookup_name)

0 commit comments

Comments
 (0)