Repository: django/django
File: tests/postgres_tests/test_array.py (Python)

Code before:
        display_value = display_for_field(
            [99, 99],
            array_field,
            self.empty_value,
        )
        self.assertEqual(display_value, self.empty_value)


class TestJSONFieldQuerying(PostgreSQLTestCase):
    def test_saving_and_querying_for_sql_null(self):
        obj = OtherTypesArrayModel.objects.create(json=[None, None])
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1__isnull=True), [obj]
        )

    def test_saving_and_querying_for_nested_none(self):
        obj = OtherTypesArrayModel.objects.create(json=[[None, 1], [None, 2]])
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1__0=None), [obj]
        )
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1__0__isnull=True), []
        )

    # RemovedInDjango70Warning.
    def test_exact_none_deprecation_warning(self):
        msg = (
            "Using None as the right-hand side of an exact lookup on JSONField to mean "
            "JSON scalar 'null' is deprecated. Use JSONNull() instead (or use the "
            "__isnull=True lookup if you meant to match SQL NULL)."
        )
        with self.assertWarnsMessage(RemovedInDjango70Warning, msg):
            list(OtherTypesArrayModel.objects.filter(json__0=None))


Review comment (bug):
Might be nice to rewrite this slightly to assert against the query result so we can keep the test after we remove the deprecation warning.

When playing with that locally, I noticed that the behavior of this query already changes in this PR, when I would have expected it to change only in the future/django 7 like JSONField. Do you know why this is?

I don't have an opinion yet if we have to have a deprecation period for this kind of change, if it turns out to be more of a bugfix.

Code after:

        display_value = display_for_field(
            [99, 99],
            array_field,
            self.empty_value,
        )
        self.assertEqual(display_value, self.empty_value)


class TestJSONFieldQuerying(PostgreSQLTestCase):
    def test_saving_and_querying_for_sql_null(self):
        obj = OtherTypesArrayModel.objects.create(json=[None, None])
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1__isnull=True), [obj]
        )
        # RemovedInDjango70Warning.
        msg = (
            "Using None as the right-hand side of an exact lookup on JSONField to mean "
            "JSON scalar 'null' is deprecated. Use JSONNull() instead (or use the "
            "__isnull lookup if you meant SQL NULL)."
        )
        with self.assertWarnsMessage(RemovedInDjango70Warning, msg):
            # RemovedInDjango70Warning: deindent, and replace [] with [obj].
            self.assertSequenceEqual(
                OtherTypesArrayModel.objects.filter(json__1=None), []
            )

    def test_saving_and_querying_for_json_null(self):
        obj = OtherTypesArrayModel.objects.create(json=[JSONNull(), JSONNull()])
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1=JSONNull()), [obj]
        )
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1__isnull=True), []
        )

    def test_saving_and_querying_for_nested_json_nulls(self):
        obj = OtherTypesArrayModel.objects.create(json=[[None, 1], [None, 2]])
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1__0=None), [obj]
        )
        self.assertSequenceEqual(
            OtherTypesArrayModel.objects.filter(json__1__0__isnull=True), []
        )