Repository: django/django
File: tests/lookup/tests.py (Python)

Code before:
    def test_in_lookup_in_filter(self):
        test_cases = [
            ((), ()),
            ((1942,), (self.s1,)),
            ((1842,), (self.s2,)),
            ((2042,), (self.s3,)),
            ((1942, 1842), (self.s1, self.s2)),
            ((1942, 2042), (self.s1, self.s3)),
            ((1842, 2042), (self.s2, self.s3)),
            ((1942, 1942, 1942), (self.s1,)),
            ((1942, 2042, 1842), (self.s1, self.s2, self.s3)),
        ]

        for years, seasons in test_cases:
            with self.subTest(years=years, seasons=seasons):
                self.assertSequenceEqual(
                    Season.objects.filter(In(F("year"), years)).order_by("pk"), seasons
                )

    def test_filter_lookup_lhs(self):
        qs = Season.objects.annotate(before_20=LessThan(F("year"), 2000)).filter(
            before_20=LessThan(F("year"), 1900),
        )
        self.assertCountEqual(qs, [self.s2, self.s3])

    def test_filter_wrapped_lookup_lhs(self):
        qs = (
            Season.objects.annotate(
                before_20=ExpressionWrapper(
                    Q(year__lt=2000),
                    output_field=BooleanField(),
                )
            )
            .filter(before_20=LessThan(F("year"), 1900))
            .values_list("year", flat=True)
        )
        self.assertCountEqual(qs, [1842, 2042])

    def test_filter_exists_lhs(self):
        qs = Season.objects.annotate(
            before_20=Exists(
                Season.objects.filter(pk=OuterRef("pk"), year__lt=2000),
            )
        ).filter(before_20=LessThan(F("year"), 1900))
        self.assertCountEqual(qs, [self.s2, self.s3])

    def test_filter_subquery_lhs(self):
        qs = Season.objects.annotate(
            before_20=Subquery(
                Season.objects.filter(pk=OuterRef("pk")).values(
                    lesser=LessThan(F("year"), 2000),

Review comment (bug):
This test crashes on Oracle because blob fields (e.g. `NCLOB`) are not allowed in the `IN()` clause. As far as I'm aware `TextFields` are unnecessary here, see #20453.

Code after:
    def test_in_lookup_in_filter(self):
        test_cases = [
            ((), ()),
            ((1942,), (self.s1,)),
            ((1842,), (self.s2,)),
            ((2042,), (self.s3,)),
            ((1942, 1842), (self.s1, self.s2)),
            ((1942, 2042), (self.s1, self.s3)),
            ((1842, 2042), (self.s2, self.s3)),
            ((1942, 1942, 1942), (self.s1,)),
            ((1942, 2042, 1842), (self.s1, self.s2, self.s3)),
        ]

        for years, seasons in test_cases:
            with self.subTest(years=years, seasons=seasons):
                self.assertSequenceEqual(
                    Season.objects.filter(In(F("year"), years)).order_by("pk"), seasons
                )

    def test_in_lookup_in_filter_text_field(self):
        self.assertSequenceEqual(
            Season.objects.filter(
                In(F("nulled_text_field"), [F("nulled_text_field"), "special_value"])
            ),
            [self.s2],
        )

    def test_filter_lookup_lhs(self):
        qs = Season.objects.annotate(before_20=LessThan(F("year"), 2000)).filter(
            before_20=LessThan(F("year"), 1900),
        )
        self.assertCountEqual(qs, [self.s2, self.s3])

    def test_filter_wrapped_lookup_lhs(self):
        qs = (
            Season.objects.annotate(
                before_20=ExpressionWrapper(
                    Q(year__lt=2000),
                    output_field=BooleanField(),
                )
            )
            .filter(before_20=LessThan(F("year"), 1900))
            .values_list("year", flat=True)
        )
        self.assertCountEqual(qs, [1842, 2042])

    def test_filter_exists_lhs(self):
        qs = Season.objects.annotate(
            before_20=Exists(
                Season.objects.filter(pk=OuterRef("pk"), year__lt=2000),
            )