django-bulk-hooks 0.1.133__tar.gz → 0.1.134__tar.gz

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.

Files changed (17) hide show
  1. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/PKG-INFO +1 -1
  2. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/queryset.py +37 -33
  3. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/pyproject.toml +1 -1
  4. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/LICENSE +0 -0
  5. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/README.md +0 -0
  6. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/__init__.py +0 -0
  7. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/conditions.py +0 -0
  8. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/constants.py +0 -0
  9. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/context.py +0 -0
  10. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/decorators.py +0 -0
  11. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/engine.py +0 -0
  12. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/enums.py +0 -0
  13. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/handler.py +0 -0
  14. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/manager.py +0 -0
  15. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/models.py +0 -0
  16. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/priority.py +0 -0
  17. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.134}/django_bulk_hooks/registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.133
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
@@ -371,48 +371,52 @@ 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: Use Django's internal _batched_insert method directly
374
+ # Step 2.5: Use Django's internal bulk_create infrastructure
375
375
  if all_child_objects:
376
- print(f"DEBUG: Using Django's internal _batched_insert for {len(all_child_objects)} child objects")
376
+ print(f"DEBUG: Using Django's internal bulk_create infrastructure for {len(all_child_objects)} child objects")
377
377
 
378
378
  # Get the base manager's queryset
379
379
  base_qs = child_model._base_manager.using(self.db)
380
380
 
381
- # Use Django's internal _batched_insert method directly
382
- # This bypasses the MTI check but uses Django's optimized bulk insert
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
383
388
  opts = child_model._meta
384
389
  fields = [f for f in opts.concrete_fields if not f.generated]
385
390
 
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
391
  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
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
416
420
 
417
421
  print(f"DEBUG: Successfully bulk created child objects using Django's internal methods")
418
422
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django-bulk-hooks"
3
- version = "0.1.133"
3
+ version = "0.1.134"
4
4
  description = "Hook-style hooks for Django bulk operations like bulk_create and bulk_update."
5
5
  authors = ["Konrad Beck <konrad.beck@merchantcapital.co.za>"]
6
6
  readme = "README.md"