django-bulk-hooks 0.1.133__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.
- django_bulk_hooks/queryset.py +37 -33
- {django_bulk_hooks-0.1.133.dist-info → django_bulk_hooks-0.1.134.dist-info}/METADATA +1 -1
- {django_bulk_hooks-0.1.133.dist-info → django_bulk_hooks-0.1.134.dist-info}/RECORD +5 -5
- {django_bulk_hooks-0.1.133.dist-info → django_bulk_hooks-0.1.134.dist-info}/LICENSE +0 -0
- {django_bulk_hooks-0.1.133.dist-info → django_bulk_hooks-0.1.134.dist-info}/WHEEL +0 -0
django_bulk_hooks/queryset.py
CHANGED
|
@@ -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
|
|
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 internal
|
|
382
|
-
# This
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -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=
|
|
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.
|
|
15
|
-
django_bulk_hooks-0.1.
|
|
16
|
-
django_bulk_hooks-0.1.
|
|
17
|
-
django_bulk_hooks-0.1.
|
|
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,,
|
|
File without changes
|
|
File without changes
|