mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #25811 -- Added a helpful error when making _in queries across different databases.
This commit is contained in:
parent
7fec264e46
commit
eb44172760
@ -203,6 +203,13 @@ class In(BuiltinLookup):
|
||||
lookup_name = 'in'
|
||||
|
||||
def process_rhs(self, compiler, connection):
|
||||
db_rhs = getattr(self.rhs, '_db', None)
|
||||
if db_rhs is not None and db_rhs != connection.alias:
|
||||
raise ValueError(
|
||||
"Subqueries aren't allowed across different databases. Force "
|
||||
"the inner query to be evaluated using `list(inner_query)`."
|
||||
)
|
||||
|
||||
if self.rhs_is_direct_value():
|
||||
try:
|
||||
rhs = set(self.rhs)
|
||||
|
@ -498,6 +498,14 @@ class LookupTests(TestCase):
|
||||
]
|
||||
)
|
||||
|
||||
def test_in_different_database(self):
|
||||
with self.assertRaisesMessage(
|
||||
ValueError,
|
||||
"Subqueries aren't allowed across different databases. Force the "
|
||||
"inner query to be evaluated using `list(inner_query)`."
|
||||
):
|
||||
list(Article.objects.filter(id__in=Article.objects.using('other').all()))
|
||||
|
||||
def test_error_messages(self):
|
||||
# Programming errors are pointed out with nice error messages
|
||||
with self.assertRaisesMessage(
|
||||
|
Loading…
Reference in New Issue
Block a user