summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/expressions/tests.py17
-rw-r--r--tests/model_fields/test_jsonfield.py3
2 files changed, 19 insertions, 1 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index d36107b358..cfa33b6f45 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -1276,6 +1276,23 @@ class IterableLookupInnerExpressionsTests(TestCase):
queryset = Result.objects.filter(**{lookup: within_experiment_time})
self.assertSequenceEqual(queryset, [r1])
+ def test_relabeled_clone_rhs(self):
+ Number.objects.bulk_create([Number(integer=1), Number(integer=2)])
+ self.assertIs(
+ Number.objects.filter(
+ # Ensure iterable of expressions are properly re-labelled on
+ # subquery pushdown. If the inner query __range right-hand-side
+ # members are not relabelled they will point at the outer query
+ # alias and this test will fail.
+ Exists(
+ Number.objects.exclude(pk=OuterRef("pk")).filter(
+ integer__range=(F("integer"), F("integer"))
+ )
+ )
+ ).exists(),
+ True,
+ )
+
class FTests(SimpleTestCase):
def test_deepcopy(self):
diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py
index 09f95ce69f..5a9cf9ad7a 100644
--- a/tests/model_fields/test_jsonfield.py
+++ b/tests/model_fields/test_jsonfield.py
@@ -13,6 +13,7 @@ from django.db import (
OperationalError,
connection,
models,
+ transaction,
)
from django.db.models import (
Count,
@@ -974,7 +975,7 @@ class TestQuerying(TestCase):
("value__i__in", [False, "foo"], [self.objs[4]]),
]
for lookup, value, expected in tests:
- with self.subTest(lookup=lookup, value=value):
+ with self.subTest(lookup=lookup, value=value), transaction.atomic():
self.assertCountEqual(
NullableJSONModel.objects.filter(**{lookup: value}),
expected,