django-bulk-hooks 0.1.132__py3-none-any.whl → 0.1.133__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,50 @@ 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 _batched_insert method directly
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 _batched_insert 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 _batched_insert method directly
382
+ # This bypasses the MTI check but uses Django's optimized bulk insert
383
+ opts = child_model._meta
384
+ fields = [f for f in opts.concrete_fields if not f.generated]
385
+
386
+ # Prepare objects for bulk insert (same logic as Django's bulk_create)
387
+ objs_with_pk, objs_without_pk = base_qs._prepare_for_bulk_create(all_child_objects)
388
+
389
+ with transaction.atomic(using=self.db, savepoint=False):
390
+ if objs_with_pk:
391
+ returned_columns = base_qs._batched_insert(
392
+ objs_with_pk,
393
+ fields,
394
+ batch_size=None,
395
+ )
396
+ for obj_with_pk, results in zip(objs_with_pk, returned_columns):
397
+ for result, field in zip(results, opts.db_returning_fields):
398
+ if field != opts.pk:
399
+ setattr(obj_with_pk, field.attname, result)
400
+ for obj_with_pk in objs_with_pk:
401
+ obj_with_pk._state.adding = False
402
+ obj_with_pk._state.db = self.db
403
+
404
+ if objs_without_pk:
405
+ fields = [f for f in fields if not isinstance(f, AutoField)]
406
+ returned_columns = base_qs._batched_insert(
407
+ objs_without_pk,
408
+ fields,
409
+ batch_size=None,
410
+ )
411
+ for obj_without_pk, results in zip(objs_without_pk, returned_columns):
412
+ for result, field in zip(results, opts.db_returning_fields):
413
+ setattr(obj_without_pk, field.attname, result)
414
+ obj_without_pk._state.adding = False
415
+ obj_without_pk._state.db = self.db
416
+
417
+ print(f"DEBUG: Successfully bulk created child objects using Django's internal methods")
388
418
 
389
419
  # Step 3: Update original objects with generated PKs and state
390
420
  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.133
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=0ocXCPiFDH-16RSj6glNHfuebixDuvVF36svqtjIgLA,21680
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.133.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
+ django_bulk_hooks-0.1.133.dist-info/METADATA,sha256=COVQFxmpj6XJ1v56jd3jWDeOptUdWKidTrwM1Vx9Zjs,6951
16
+ django_bulk_hooks-0.1.133.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
+ django_bulk_hooks-0.1.133.dist-info/RECORD,,