django-bulk-hooks 0.1.132__py3-none-any.whl → 0.1.134__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of django-bulk-hooks might be problematic. Click here for more details.

@@ -371,20 +371,54 @@ class HookQuerySet(models.QuerySet):
371
371
  all_child_objects.append(child_obj)
372
372
  print(f"DEBUG: Created {len(all_child_objects)} child objects")
373
373
 
374
- # Step 2.5: Single bulk insert into childmost table
374
+ # Step 2.5: Use Django's internal bulk_create infrastructure
375
375
  if all_child_objects:
376
- print(f"DEBUG: Attempting to bulk_create {len(all_child_objects)} child objects for {child_model.__name__}")
377
- try:
378
- # Use Django's internal bulk_create to bypass MTI exception
379
- child_model._base_manager.bulk_create(all_child_objects)
380
- print(f"DEBUG: Successfully bulk_created child objects")
381
- except ValueError as e:
382
- print(f"DEBUG: bulk_create failed with error: {e}")
383
- print(f"DEBUG: Falling back to individual creates for child objects")
384
- # Fall back to individual creates if bulk_create fails
385
- for child_obj in all_child_objects:
386
- child_obj.save(using=self.db)
387
- print(f"DEBUG: Successfully created child objects individually")
376
+ print(f"DEBUG: Using Django's internal bulk_create infrastructure for {len(all_child_objects)} child objects")
377
+
378
+ # Get the base manager's queryset
379
+ base_qs = child_model._base_manager.using(self.db)
380
+
381
+ # Use Django's internal _prepare_for_bulk_create method
382
+ # This is the same method that Django's bulk_create uses internally
383
+ objs_with_pk, objs_without_pk = base_qs._prepare_for_bulk_create(all_child_objects)
384
+
385
+ print(f"DEBUG: Prepared {len(objs_with_pk)} objects with PK, {len(objs_without_pk)} objects without PK")
386
+
387
+ # Use Django's internal _batched_insert method
388
+ opts = child_model._meta
389
+ fields = [f for f in opts.concrete_fields if not f.generated]
390
+
391
+ with transaction.atomic(using=self.db, savepoint=False):
392
+ if objs_with_pk:
393
+ print(f"DEBUG: Inserting {len(objs_with_pk)} objects with PK")
394
+ returned_columns = base_qs._batched_insert(
395
+ objs_with_pk,
396
+ fields,
397
+ batch_size=len(objs_with_pk), # Use actual batch size
398
+ )
399
+ for obj_with_pk, results in zip(objs_with_pk, returned_columns):
400
+ for result, field in zip(results, opts.db_returning_fields):
401
+ if field != opts.pk:
402
+ setattr(obj_with_pk, field.attname, result)
403
+ for obj_with_pk in objs_with_pk:
404
+ obj_with_pk._state.adding = False
405
+ obj_with_pk._state.db = self.db
406
+
407
+ if objs_without_pk:
408
+ print(f"DEBUG: Inserting {len(objs_without_pk)} objects without PK")
409
+ fields = [f for f in fields if not isinstance(f, AutoField)]
410
+ returned_columns = base_qs._batched_insert(
411
+ objs_without_pk,
412
+ fields,
413
+ batch_size=len(objs_without_pk), # Use actual batch size
414
+ )
415
+ for obj_without_pk, results in zip(objs_without_pk, returned_columns):
416
+ for result, field in zip(results, opts.db_returning_fields):
417
+ setattr(obj_without_pk, field.attname, result)
418
+ obj_without_pk._state.adding = False
419
+ obj_without_pk._state.db = self.db
420
+
421
+ print(f"DEBUG: Successfully bulk created child objects using Django's internal methods")
388
422
 
389
423
  # Step 3: Update original objects with generated PKs and state
390
424
  pk_field_name = child_model._meta.pk.name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.132
3
+ Version: 0.1.134
4
4
  Summary: Hook-style hooks for Django bulk operations like bulk_create and bulk_update.
5
5
  License: MIT
6
6
  Keywords: django,bulk,hooks
@@ -9,9 +9,9 @@ django_bulk_hooks/handler.py,sha256=xZt8iNdYF-ACz-MnKMY0co6scWINU5V5wC1lyDn844k,
9
9
  django_bulk_hooks/manager.py,sha256=r54ct3S6AcqME2OsX-jPF944CEKcoSIW3qiAx_NwUaw,2801
10
10
  django_bulk_hooks/models.py,sha256=7RG7GrOdHXFjGVPV4FPRZVNMIHHW-hMCi6hn9LH_hVI,3331
11
11
  django_bulk_hooks/priority.py,sha256=HG_2D35nga68lBCZmSXTcplXrjFoRgZFRDOy4ROKonY,376
12
- django_bulk_hooks/queryset.py,sha256=0CfSUANNj6bJ2ZyYK8CVSYCk18QqQ-ir7rbYAsPmxog,20147
12
+ django_bulk_hooks/queryset.py,sha256=t402vyqe55YR8t_sAlYrYvaZ3Eokm8T3byWPvj4ujB8,22073
13
13
  django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
14
- django_bulk_hooks-0.1.132.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.132.dist-info/METADATA,sha256=Ll3JnV4XaiqF7_yELa2NPB60Mdz-im4H96JHyWKF450,6951
16
- django_bulk_hooks-0.1.132.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.132.dist-info/RECORD,,
14
+ django_bulk_hooks-0.1.134.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
+ django_bulk_hooks-0.1.134.dist-info/METADATA,sha256=hj79PjeJAopmRDrqSe1NXxbshsPLyQruNmC6Vnnvwf4,6951
16
+ django_bulk_hooks-0.1.134.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
+ django_bulk_hooks-0.1.134.dist-info/RECORD,,