summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClifford Gama <cliffygamy@gmail.com>2025-08-27 14:24:47 +0200
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-22 14:20:07 -0500
commit9cc5c87ffb989991524ee4eb91a435d2296ded2b (patch)
tree1d15c41735cd384a8f8b4eefa79dd9b326849ce7 /tests
parentd0d85cd165e54582cce98cf685252e771460a9d4 (diff)
Replaced per-object create() calls with bulk_create in tests/model_fields/test_jsonfield.py
Diffstat (limited to 'tests')
-rw-r--r--tests/model_fields/test_jsonfield.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py
index d0561e14d2..76cdc0e421 100644
--- a/tests/model_fields/test_jsonfield.py
+++ b/tests/model_fields/test_jsonfield.py
@@ -364,14 +364,14 @@ class TestQuerying(TestCase):
"bax": {"foo": "bar"},
},
]
- cls.objs = [NullableJSONModel.objects.create(value=value) for value in values]
+ objs = [NullableJSONModel(value=value) for value in values]
if connection.features.supports_primitives_in_json_field:
- cls.objs.extend(
- [
- NullableJSONModel.objects.create(value=value)
- for value in cls.primitives
- ]
- )
+ objs.extend([NullableJSONModel(value=value) for value in cls.primitives])
+ objs = NullableJSONModel.objects.bulk_create(objs)
+ # Some backends don't return primary keys after bulk_create.
+ if any(obj.pk is None for obj in objs):
+ objs = list(NullableJSONModel.objects.order_by("id"))
+ cls.objs = objs
cls.raw_sql = "%s::jsonb" if connection.vendor == "postgresql" else "%s"
def test_exact(self):