django-bulk-hooks 0.1.131__py3-none-any.whl → 0.1.132__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.

@@ -97,10 +97,15 @@ class HookQuerySet(models.QuerySet):
97
97
  # MultiTableParent -> ProxyChild. Simply checking self.model._meta.proxy would not
98
98
  # identify that case as involving multiple tables.
99
99
  is_mti = False
100
+ print(f"DEBUG: Checking for MTI on {model_cls.__name__}")
101
+ print(f"DEBUG: All parents: {[p.__name__ for p in model_cls._meta.all_parents]}")
100
102
  for parent in model_cls._meta.all_parents:
103
+ print(f"DEBUG: Checking parent {parent.__name__} (concrete: {parent._meta.concrete_model.__name__}) vs {model_cls.__name__} (concrete: {model_cls._meta.concrete_model.__name__})")
101
104
  if parent._meta.concrete_model is not model_cls._meta.concrete_model:
102
105
  is_mti = True
106
+ print(f"DEBUG: MTI detected! {parent.__name__} and {model_cls.__name__} have different concrete models")
103
107
  break
108
+ print(f"DEBUG: Final MTI result: {is_mti}")
104
109
 
105
110
  if not objs:
106
111
  return objs
@@ -119,6 +124,7 @@ class HookQuerySet(models.QuerySet):
119
124
 
120
125
  # For MTI models, we need to handle them specially
121
126
  if is_mti:
127
+ print(f"DEBUG: Using MTI-specific logic for {model_cls.__name__}")
122
128
  # Use our MTI-specific logic
123
129
  result = self._mti_bulk_create(
124
130
  objs,
@@ -129,6 +135,7 @@ class HookQuerySet(models.QuerySet):
129
135
  unique_fields=unique_fields,
130
136
  )
131
137
  else:
138
+ print(f"DEBUG: Using standard bulk_create for {model_cls.__name__}")
132
139
  # For single-table models, use Django's built-in bulk_create
133
140
  # but we need to call it on the base manager to avoid recursion
134
141
 
@@ -325,10 +332,13 @@ class HookQuerySet(models.QuerySet):
325
332
  parent_objects_map = {}
326
333
 
327
334
  # Step 1: Do O(n) normal inserts into parent tables to get primary keys back
335
+ print(f"DEBUG: Processing batch of {len(batch)} objects")
336
+ print(f"DEBUG: Inheritance chain: {[m.__name__ for m in inheritance_chain]}")
328
337
  for obj in batch:
329
338
  parent_instances = {}
330
339
  current_parent = None
331
340
  for model_class in inheritance_chain[:-1]:
341
+ print(f"DEBUG: Creating parent instance for {model_class.__name__}")
332
342
  parent_obj = self._create_parent_instance(
333
343
  obj, model_class, current_parent
334
344
  )
@@ -339,7 +349,9 @@ class HookQuerySet(models.QuerySet):
339
349
  for field in model_class._meta.local_fields
340
350
  if hasattr(parent_obj, field.name) and getattr(parent_obj, field.name) is not None
341
351
  }
352
+ print(f"DEBUG: Creating {model_class.__name__} with field_values: {field_values}")
342
353
  created_obj = model_class._base_manager.using(self.db).create(**field_values)
354
+ print(f"DEBUG: Created {model_class.__name__} with PK: {created_obj.pk}")
343
355
  # Update the parent_obj with the created object's PK
344
356
  parent_obj.pk = created_obj.pk
345
357
  parent_obj._state.adding = False
@@ -350,25 +362,41 @@ class HookQuerySet(models.QuerySet):
350
362
 
351
363
  # Step 2: Create all child objects and do single bulk insert into childmost table
352
364
  child_model = inheritance_chain[-1]
365
+ print(f"DEBUG: Creating child objects for {child_model.__name__}")
353
366
  all_child_objects = []
354
367
  for obj in batch:
355
368
  child_obj = self._create_child_instance(
356
369
  obj, child_model, parent_objects_map.get(id(obj), {})
357
370
  )
358
371
  all_child_objects.append(child_obj)
372
+ print(f"DEBUG: Created {len(all_child_objects)} child objects")
359
373
 
360
374
  # Step 2.5: Single bulk insert into childmost table
361
375
  if all_child_objects:
362
- # Use Django's internal bulk_create to bypass MTI exception
363
- child_model._base_manager.bulk_create(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")
364
388
 
365
389
  # Step 3: Update original objects with generated PKs and state
366
390
  pk_field_name = child_model._meta.pk.name
391
+ print(f"DEBUG: Updating original objects with PK field: {pk_field_name}")
367
392
  for orig_obj, child_obj in zip(batch, all_child_objects):
368
- setattr(orig_obj, pk_field_name, getattr(child_obj, pk_field_name))
393
+ child_pk = getattr(child_obj, pk_field_name)
394
+ print(f"DEBUG: Setting {orig_obj.__class__.__name__} PK to {child_pk}")
395
+ setattr(orig_obj, pk_field_name, child_pk)
369
396
  orig_obj._state.adding = False
370
397
  orig_obj._state.db = self.db
371
398
 
399
+ print(f"DEBUG: Completed processing batch")
372
400
  return batch
373
401
 
374
402
  def _create_parent_instance(self, source_obj, parent_model, current_parent):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.131
3
+ Version: 0.1.132
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=rOxkIV5dj72njbzZH8WJGdleaa1ukqHFFNzmDnoAZoc,17952
12
+ django_bulk_hooks/queryset.py,sha256=0CfSUANNj6bJ2ZyYK8CVSYCk18QqQ-ir7rbYAsPmxog,20147
13
13
  django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
14
- django_bulk_hooks-0.1.131.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.131.dist-info/METADATA,sha256=mMjng3pfCbLJiDNqqJ3aXOBctF1aDoumVg1YxFLeuE0,6951
16
- django_bulk_hooks-0.1.131.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.131.dist-info/RECORD,,
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,,