Ticket #35381: json_null_tests.patch

File json_null_tests.patch, 1.3 KB (added by Olivier Tabone, 7 months ago)
  • new file tests/json_null_tests/models.py

    diff --git a/tests/json_null_tests/__init__.py b/tests/json_null_tests/__init__.py
    new file mode 100644
    index 0000000000..e69de29bb2
    diff --git a/tests/json_null_tests/models.py b/tests/json_null_tests/models.py
    new file mode 100644
    index 0000000000..c4a30b3047
    - +  
     1from django.db import models
     2
     3
     4class JSONFieldModel(models.Model):
     5    data = models.JSONField(null=True, blank=True, default=None)
     6
     7    class Meta:
     8        required_db_features = {"supports_json_field"}
     9        constraints = [
     10            models.CheckConstraint(
     11                check=~models.Q(data=models.Value(None, models.JSONField())),
     12                name="json_data_cant_be_json_null",
     13            ),
     14        ]
  • new file tests/json_null_tests/tests.py

    diff --git a/tests/json_null_tests/tests.py b/tests/json_null_tests/tests.py
    new file mode 100644
    index 0000000000..0488040dfa
    - +  
     1from django.test import TestCase, skipUnlessDBFeature
     2
     3from .models import JSONFieldModel
     4
     5
     6class CheckConstraintTests(TestCase):
     7    @skipUnlessDBFeature("supports_json_field")
     8    def test_full_clean_on_null_value(self):
     9        instance = JSONFieldModel.objects.create(data=None)  # data = SQL Null value
     10        instance.full_clean()
Back to Top