diff options
| author | Clifford Gama <cliffygamy@gmail.com> | 2025-08-27 14:24:47 +0200 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-12-22 14:20:07 -0500 |
| commit | 9cc5c87ffb989991524ee4eb91a435d2296ded2b (patch) | |
| tree | 1d15c41735cd384a8f8b4eefa79dd9b326849ce7 /tests/model_fields | |
| parent | d0d85cd165e54582cce98cf685252e771460a9d4 (diff) | |
Replaced per-object create() calls with bulk_create in tests/model_fields/test_jsonfield.py
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/test_jsonfield.py | 14 |
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): |
