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.
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/PKG-INFO +1 -1
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/queryset.py +42 -33
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/pyproject.toml +1 -1
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/LICENSE +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/README.md +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/__init__.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/conditions.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/constants.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/context.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/decorators.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/engine.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/enums.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/handler.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/manager.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/models.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/priority.py +0 -0
- {django_bulk_hooks-0.1.133 → django_bulk_hooks-0.1.135}/django_bulk_hooks/registry.py +0 -0
|
@@ -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
|
|
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
|
|
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
|
|
382
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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.
|
|
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"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|