| 300 | |
| 301 | # Regression tests for #30827 |
| 302 | def test_batched_insert_on_model_without_pk(self): |
| 303 | objs = [Country(name=str(i), iso_two_letter=str(i), description=str(i)) |
| 304 | for i in range(1000)] |
| 305 | ops = connections[Country.objects.db].ops |
| 306 | opts = Country.objects.model._meta |
| 307 | fields = [f for f in opts.concrete_fields if not isinstance(f, AutoField)] |
| 308 | max_batch_size = max(ops.bulk_batch_size(fields, objs), 1) |
| 309 | with self.assertNumQueries(ceil(1000/max_batch_size)): |
| 310 | Country.objects.bulk_create(objs, batch_size = max_batch_size + 1) |
| 311 | |
| 312 | # Regression tests for #30827 |
| 313 | def test_batched_insert_upper_limit(self): |
| 314 | ops = connections[State.objects.db].ops |
| 315 | opts = State.objects.model._meta |
| 316 | fields = opts.concrete_fields |
| 317 | objs = [State(two_letter_code=str(i)) |
| 318 | for i in range(1000)] |
| 319 | max_batch_size = max(ops.bulk_batch_size(fields, objs), 1) |
| 320 | try: |
| 321 | State.objects.bulk_create(objs, batch_size = max_batch_size + 1) |
| 322 | except OperationalError as e: |
| 323 | self.fail("Unexpected failure while performing regresion test in " |
| 324 | "bulk_create: %s" % e) |