mirror of https://github.com/django/django.git
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'
|
lookup_name = 'in'
|
||||||
|
|
||||||
def process_rhs(self, compiler, connection):
|
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():
|
if self.rhs_is_direct_value():
|
||||||
try:
|
try:
|
||||||
rhs = set(self.rhs)
|
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):
|
def test_error_messages(self):
|
||||||
# Programming errors are pointed out with nice error messages
|
# Programming errors are pointed out with nice error messages
|
||||||
with self.assertRaisesMessage(
|
with self.assertRaisesMessage(
|
||||||
|
|
Loading…
Reference in New Issue