diff options
| author | Kanin Kearpimy <kanin.kearpimy@gmail.com> | 2026-03-11 13:06:40 +0000 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-03-16 11:53:25 -0400 |
| commit | d7bf84324fb4b0789302bd0624697ba973dd7140 (patch) | |
| tree | 6031d498b1f48d5ec9a7841212704f5b8d083138 /tests/model_fields | |
| parent | ad5ea292748246b2f07f3e379a250985c1ebcba5 (diff) | |
Fixed #36906 -- Handled coalescing JSON-primitive strings and JSON values on Oracle.
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/models.py | 1 | ||||
| -rw-r--r-- | tests/model_fields/test_jsonfield.py | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index a594b89adb..c1e356bb53 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -452,6 +452,7 @@ class JSONNullDefaultModel(models.Model): class RelatedJSONModel(models.Model): value = models.JSONField() json_model = models.ForeignKey(NullableJSONModel, models.CASCADE) + summary = models.CharField(max_length=100, null=True, blank=True) class Meta: required_db_features = {"supports_json_field"} diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py index 1afeef31eb..7b07a48a1e 100644 --- a/tests/model_fields/test_jsonfield.py +++ b/tests/model_fields/test_jsonfield.py @@ -40,7 +40,7 @@ from django.db.models.fields.json import ( KeyTransformFactory, KeyTransformTextLookupMixin, ) -from django.db.models.functions import Cast +from django.db.models.functions import Cast, Coalesce from django.test import ( SimpleTestCase, TestCase, @@ -1290,6 +1290,20 @@ class TestQuerying(TestCase): ) self.assertQuerySetEqual(qs, all_objects) + @skipUnlessDBFeature("supports_primitives_in_json_field") + def test_json_type_casting_with_coalesce(self): + RelatedJSONModel.objects.create( + summary='"This is valid JSON primitive."', + value={"text": "test"}, + json_model=self.objs[4], + ) + result = RelatedJSONModel.objects.annotate( + coalesced_value=Coalesce( + Cast("summary", JSONField()), "value", output_field=JSONField() + ) + ).first() + self.assertEqual(result.coalesced_value, "This is valid JSON primitive.") + @skipUnlessDBFeature("supports_primitives_in_json_field") class JSONNullTests(TestCase): |
