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

@@ -7,22 +7,38 @@ from django_bulk_hooks.registry import get_hooks
7
7
  logger = logging.getLogger(__name__)
8
8
 
9
9
 
10
- def run(model_cls, event, new_instances, original_instances=None, ctx=None):
11
- hooks = get_hooks(model_cls, event)
10
+ def run(model_cls, event, new_records, old_records=None, ctx=None):
11
+ """
12
+ Run hooks for a given model, event, and records.
13
+ """
14
+ print(f"DEBUG: engine.run called for {model_cls} with event {event}")
15
+ print(f"DEBUG: Number of new_records: {len(new_records) if new_records else 0}")
16
+ print(f"DEBUG: Number of old_records: {len(old_records) if old_records else 0}")
17
+
18
+ if not new_records:
19
+ print(f"DEBUG: No new_records, skipping hooks")
20
+ return
12
21
 
22
+ # Get hooks for this model and event
23
+ hooks = get_hooks(model_cls, event)
24
+ print(f"DEBUG: Found {len(hooks)} hooks for {model_cls}.{event}")
25
+
13
26
  if not hooks:
27
+ print(f"DEBUG: No hooks found for {model_cls}.{event}")
14
28
  return
15
29
 
16
30
  # For BEFORE_* events, run model.clean() first for validation
17
31
  if event.startswith("before_"):
18
- for instance in new_instances:
32
+ for instance in new_records:
19
33
  try:
20
34
  instance.clean()
21
35
  except ValidationError as e:
22
36
  logger.error("Validation failed for %s: %s", instance, e)
23
37
  raise
24
38
 
39
+ # Process hooks
25
40
  for handler_cls, method_name, condition, priority in hooks:
41
+ print(f"DEBUG: Processing hook: {handler_cls.__name__}.{method_name}")
26
42
  handler_instance = handler_cls()
27
43
  func = getattr(handler_instance, method_name)
28
44
 
@@ -30,14 +46,28 @@ def run(model_cls, event, new_instances, original_instances=None, ctx=None):
30
46
  to_process_old = []
31
47
 
32
48
  for new, original in zip(
33
- new_instances,
34
- original_instances or [None] * len(new_instances),
49
+ new_records,
50
+ old_records or [None] * len(new_records),
35
51
  strict=True,
36
52
  ):
53
+ print(f"DEBUG: Checking condition for {handler_cls.__name__}.{method_name}")
54
+ print(f"DEBUG: - new: {type(new)}")
55
+ print(f"DEBUG: - original: {type(original)}")
56
+ print(f"DEBUG: - condition: {condition}")
37
57
  if not condition or condition.check(new, original):
58
+ print(f"DEBUG: - condition passed, adding to process list")
38
59
  to_process_new.append(new)
39
60
  to_process_old.append(original)
61
+ else:
62
+ print(f"DEBUG: - condition failed, skipping")
40
63
 
41
64
  if to_process_new:
42
- # Call the function with keyword arguments
43
- func(new_records=to_process_new, old_records=to_process_old if any(to_process_old) else None)
65
+ print(f"DEBUG: Executing hook {handler_cls.__name__}.{method_name} with {len(to_process_new)} records")
66
+ try:
67
+ func(new_records=to_process_new, old_records=to_process_old if any(to_process_old) else None)
68
+ print(f"DEBUG: Hook {handler_cls.__name__}.{method_name} executed successfully")
69
+ except Exception as e:
70
+ print(f"DEBUG: Hook {handler_cls.__name__}.{method_name} failed with error: {e}")
71
+ raise
72
+ else:
73
+ print(f"DEBUG: Skipping hook {handler_cls.__name__}.{method_name} - no records to process")
@@ -5,7 +5,10 @@ from django_bulk_hooks.queryset import HookQuerySet
5
5
 
6
6
  class BulkHookManager(models.Manager):
7
7
  def get_queryset(self):
8
- return HookQuerySet(self.model, using=self._db)
8
+ qs = HookQuerySet(self.model, using=self._db)
9
+ print(f"DEBUG: BulkHookManager.get_queryset() called for {self.model}")
10
+ print(f"DEBUG: Returning QuerySet type: {type(qs)}")
11
+ return qs
9
12
 
10
13
  def bulk_update(
11
14
  self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs
@@ -20,6 +23,8 @@ class BulkHookManager(models.Manager):
20
23
  print(f"DEBUG: bulk_update method signature: {inspect.signature(method)}")
21
24
  print(f"DEBUG: Calling with args: objs={type(objs)}, fields={fields}, bypass_hooks={bypass_hooks}, bypass_validation={bypass_validation}, kwargs={kwargs}")
22
25
  print(f"DEBUG: QuerySet class: {type(qs)}")
26
+ print(f"DEBUG: Manager type: {type(self)}")
27
+ print(f"DEBUG: Model: {self.model}")
23
28
 
24
29
  # Check if this is our HookQuerySet or a different QuerySet
25
30
  if hasattr(qs, 'bulk_update') and 'bypass_hooks' in inspect.signature(qs.bulk_update).parameters:
@@ -113,9 +113,15 @@ class HookQuerySet(models.QuerySet):
113
113
  # Fire hooks before DB ops
114
114
  if not bypass_hooks:
115
115
  print(f"DEBUG: Firing BEFORE_CREATE hooks for {model_cls}")
116
+ print(f"DEBUG: Number of objects: {len(objs)}")
117
+ print(f"DEBUG: Object types: {[type(obj) for obj in objs]}")
118
+ print(f"DEBUG: QuerySet type: {type(self)}")
119
+ print(f"DEBUG: Is this HookQuerySet? {isinstance(self, HookQuerySet)}")
116
120
  ctx = HookContext(model_cls)
117
121
  if not bypass_validation:
122
+ print(f"DEBUG: Running VALIDATE_CREATE hooks")
118
123
  engine.run(model_cls, VALIDATE_CREATE, objs, ctx=ctx)
124
+ print(f"DEBUG: Running BEFORE_CREATE hooks")
119
125
  engine.run(model_cls, BEFORE_CREATE, objs, ctx=ctx)
120
126
  else:
121
127
  print(f"DEBUG: Skipping hooks due to bypass_hooks=True for {model_cls}")
@@ -156,6 +162,9 @@ class HookQuerySet(models.QuerySet):
156
162
  # Fire AFTER_CREATE hooks
157
163
  if not bypass_hooks:
158
164
  print(f"DEBUG: Firing AFTER_CREATE hooks for {model_cls}")
165
+ print(f"DEBUG: Number of objects: {len(objs)}")
166
+ print(f"DEBUG: QuerySet type: {type(self)}")
167
+ print(f"DEBUG: Is this HookQuerySet? {isinstance(self, HookQuerySet)}")
159
168
  engine.run(model_cls, AFTER_CREATE, objs, ctx=ctx)
160
169
  else:
161
170
  print(f"DEBUG: Skipping AFTER_CREATE hooks due to bypass_hooks=True for {model_cls}")
@@ -180,6 +189,8 @@ class HookQuerySet(models.QuerySet):
180
189
  model_cls = self.model
181
190
  print(f"DEBUG: Model class: {model_cls}")
182
191
  print(f"DEBUG: bypass_hooks value: {bypass_hooks}")
192
+ print(f"DEBUG: QuerySet type: {type(self)}")
193
+ print(f"DEBUG: Is this HookQuerySet? {isinstance(self, HookQuerySet)}")
183
194
 
184
195
  if not objs:
185
196
  return []
@@ -204,7 +215,13 @@ class HookQuerySet(models.QuerySet):
204
215
  engine.run(model_cls, VALIDATE_UPDATE, objs, originals, ctx=ctx)
205
216
 
206
217
  # Then run business logic hooks
207
- engine.run(model_cls, BEFORE_UPDATE, objs, originals, ctx=ctx)
218
+ if not bypass_hooks:
219
+ print(f"DEBUG: Firing BEFORE_UPDATE hooks for {model_cls}")
220
+ print(f"DEBUG: Number of objects: {len(objs)}")
221
+ print(f"DEBUG: Object types: {[type(obj) for obj in objs]}")
222
+ engine.run(model_cls, BEFORE_UPDATE, objs, originals, ctx=ctx)
223
+ else:
224
+ print(f"DEBUG: Skipping hooks due to bypass_hooks=True for {model_cls}")
208
225
 
209
226
  # Automatically detect fields that were modified during BEFORE_UPDATE hooks
210
227
  modified_fields = self._detect_modified_fields(objs, originals)
@@ -224,6 +241,7 @@ class HookQuerySet(models.QuerySet):
224
241
 
225
242
  if not bypass_hooks:
226
243
  print(f"DEBUG: Firing AFTER_UPDATE hooks for {model_cls}")
244
+ print(f"DEBUG: Number of objects: {len(objs)}")
227
245
  engine.run(model_cls, AFTER_UPDATE, objs, originals, ctx=ctx)
228
246
  else:
229
247
  print(f"DEBUG: Skipping AFTER_UPDATE hooks due to bypass_hooks=True for {model_cls}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.164
3
+ Version: 0.1.166
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
@@ -3,15 +3,15 @@ django_bulk_hooks/conditions.py,sha256=mTvlLcttixbXRkTSNZU5VewkPUavbXRuD2BkJbVWM
3
3
  django_bulk_hooks/constants.py,sha256=3x1H1fSUUNo0DZONN7GUVDuySZctTR-jtByBHmAIX5w,303
4
4
  django_bulk_hooks/context.py,sha256=4IPuOX8TBAYBEMzN0RNHWgE6Giy2ZnR5uRXfd1cpIwk,1051
5
5
  django_bulk_hooks/decorators.py,sha256=tckDcxtOzKCbgvS9QydgeIAWTFDEl-ch3_Q--ruEGdQ,4831
6
- django_bulk_hooks/engine.py,sha256=3HbgV12JRYIy9IlygHPxZiHnFXj7EwzLyTuJNQeVIoI,1402
6
+ django_bulk_hooks/engine.py,sha256=fqd32vwpNLoph2B6O7BW2eeja8yzUzenLx3Iwj2Mz_U,2964
7
7
  django_bulk_hooks/enums.py,sha256=Zo8_tJzuzZ2IKfVc7gZ-0tWPT8q1QhqZbAyoh9ZVJbs,381
8
8
  django_bulk_hooks/handler.py,sha256=xZt8iNdYF-ACz-MnKMY0co6scWINU5V5wC1lyDn844k,4854
9
- django_bulk_hooks/manager.py,sha256=ipOr2PMGycW0LpWsZ0asNRTPKVNpp3D081ibuY__cj0,5551
9
+ django_bulk_hooks/manager.py,sha256=nccIBEWLc9T18A97ZYT1KU4JzGSOvTjBdDOxS4D5bX0,5810
10
10
  django_bulk_hooks/models.py,sha256=5PBjBoGlHwAE5b4yaZ5kDjt5UtHfQp6pDrwB2XPs2tk,3850
11
11
  django_bulk_hooks/priority.py,sha256=HG_2D35nga68lBCZmSXTcplXrjFoRgZFRDOy4ROKonY,376
12
- django_bulk_hooks/queryset.py,sha256=qMMr_IgOrWqV5dYoEqOSKjJcxgepcovdjAn77QL5bs8,23574
12
+ django_bulk_hooks/queryset.py,sha256=pdxnZKJU6eMHT-bxp3s4r8MUwaTXgnIUxgyKvN-1WB8,24723
13
13
  django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
14
- django_bulk_hooks-0.1.164.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.164.dist-info/METADATA,sha256=ctAhRwnzonbXKWblwj0eU6agetmVEhVcmvj2TqtQls0,6951
16
- django_bulk_hooks-0.1.164.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.164.dist-info/RECORD,,
14
+ django_bulk_hooks-0.1.166.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
+ django_bulk_hooks-0.1.166.dist-info/METADATA,sha256=5-zw3ByLKxog0xPphuXBcwESKyJIXRfNFLApVQSG6n4,6951
16
+ django_bulk_hooks-0.1.166.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
+ django_bulk_hooks-0.1.166.dist-info/RECORD,,