django-bulk-hooks 0.1.133__tar.gz → 0.1.135__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.135}/PKG-INFO +1 -1
  2. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/queryset.py +42 -33
  3. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/pyproject.toml +1 -1
  4. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/LICENSE +0 -0
  5. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/README.md +0 -0
  6. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/__init__.py +0 -0
  7. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/conditions.py +0 -0
  8. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/constants.py +0 -0
  9. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/context.py +0 -0
  10. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/decorators.py +0 -0
  11. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/engine.py +0 -0
  12. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/enums.py +0 -0
  13. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/handler.py +0 -0
  14. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/manager.py +0 -0
  15. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/models.py +0 -0
  16. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/priority.py +0 -0
  17. {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/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.135
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,57 @@ 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 exact approach: call _prepare_for_bulk_create then partition
382
+ base_qs._prepare_for_bulk_create(all_child_objects)
383
+
384
+ # Use partition like Django does to separate objects with PKs from those without
385
+ from itertools import partition
386
+ objs_without_pk, objs_with_pk = partition(lambda o: o._is_pk_set(), all_child_objects)
387
+ objs_without_pk = list(objs_without_pk)
388
+ objs_with_pk = list(objs_with_pk)
389
+
390
+ print(f"DEBUG: Prepared {len(objs_with_pk)} objects with PK, {len(objs_without_pk)} objects without PK")
391
+
392
+ # Use Django's internal _batched_insert method
383
393
  opts = child_model._meta
384
394
  fields = [f for f in opts.concrete_fields if not f.generated]
385
395
 
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
396
  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
397
+ if objs_with_pk:
398
+ print(f"DEBUG: Inserting {len(objs_with_pk)} objects with PK")
399
+ returned_columns = base_qs._batched_insert(
400
+ objs_with_pk,
401
+ fields,
402
+ batch_size=len(objs_with_pk), # Use actual batch size
403
+ )
404
+ for obj_with_pk, results in zip(objs_with_pk, returned_columns):
405
+ for result, field in zip(results, opts.db_returning_fields):
406
+ if field != opts.pk:
407
+ setattr(obj_with_pk, field.attname, result)
408
+ for obj_with_pk in objs_with_pk:
409
+ obj_with_pk._state.adding = False
410
+ obj_with_pk._state.db = self.db
411
+
412
+ if objs_without_pk:
413
+ print(f"DEBUG: Inserting {len(objs_without_pk)} objects without PK")
414
+ fields = [f for f in fields if not isinstance(f, AutoField)]
415
+ returned_columns = base_qs._batched_insert(
416
+ objs_without_pk,
417
+ fields,
418
+ batch_size=len(objs_without_pk), # Use actual batch size
419
+ )
420
+ for obj_without_pk, results in zip(objs_without_pk, returned_columns):
421
+ for result, field in zip(results, opts.db_returning_fields):
422
+ setattr(obj_without_pk, field.attname, result)
423
+ obj_without_pk._state.adding = False
424
+ obj_without_pk._state.db = self.db
416
425
 
417
426
  print(f"DEBUG: Successfully bulk created child objects using Django's internal methods")
418
427
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django-bulk-hooks"
3
- version = "0.1.133"
3
+ version = "0.1.135"
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"