django-bulk-hooks 0.1.163__py3-none-any.whl → 0.1.165__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/engine.py +30 -7
- django_bulk_hooks/manager.py +6 -0
- django_bulk_hooks/queryset.py +19 -1
- {django_bulk_hooks-0.1.163.dist-info → django_bulk_hooks-0.1.165.dist-info}/METADATA +1 -1
- {django_bulk_hooks-0.1.163.dist-info → django_bulk_hooks-0.1.165.dist-info}/RECORD +7 -7
- {django_bulk_hooks-0.1.163.dist-info → django_bulk_hooks-0.1.165.dist-info}/LICENSE +0 -0
- {django_bulk_hooks-0.1.163.dist-info → django_bulk_hooks-0.1.165.dist-info}/WHEEL +0 -0
django_bulk_hooks/engine.py
CHANGED
|
@@ -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,
|
|
11
|
-
|
|
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
|
|
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,8 +46,8 @@ 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
|
-
|
|
34
|
-
|
|
49
|
+
new_records,
|
|
50
|
+
old_records or [None] * len(new_records),
|
|
35
51
|
strict=True,
|
|
36
52
|
):
|
|
37
53
|
if not condition or condition.check(new, original):
|
|
@@ -39,5 +55,12 @@ def run(model_cls, event, new_instances, original_instances=None, ctx=None):
|
|
|
39
55
|
to_process_old.append(original)
|
|
40
56
|
|
|
41
57
|
if to_process_new:
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
print(f"DEBUG: Executing hook {handler_cls.__name__}.{method_name} with {len(to_process_new)} records")
|
|
59
|
+
try:
|
|
60
|
+
func(new_records=to_process_new, old_records=to_process_old if any(to_process_old) else None)
|
|
61
|
+
print(f"DEBUG: Hook {handler_cls.__name__}.{method_name} executed successfully")
|
|
62
|
+
except Exception as e:
|
|
63
|
+
print(f"DEBUG: Hook {handler_cls.__name__}.{method_name} failed with error: {e}")
|
|
64
|
+
raise
|
|
65
|
+
else:
|
|
66
|
+
print(f"DEBUG: Skipping hook {handler_cls.__name__}.{method_name} - no records to process")
|
django_bulk_hooks/manager.py
CHANGED
|
@@ -24,9 +24,11 @@ class BulkHookManager(models.Manager):
|
|
|
24
24
|
# Check if this is our HookQuerySet or a different QuerySet
|
|
25
25
|
if hasattr(qs, 'bulk_update') and 'bypass_hooks' in inspect.signature(qs.bulk_update).parameters:
|
|
26
26
|
# Our HookQuerySet - pass all parameters
|
|
27
|
+
print(f"DEBUG: Using our HookQuerySet for {self.model}")
|
|
27
28
|
return qs.bulk_update(objs, fields, bypass_hooks=bypass_hooks, bypass_validation=bypass_validation, **kwargs)
|
|
28
29
|
else:
|
|
29
30
|
# Different QuerySet (like queryable_properties) - only pass standard parameters
|
|
31
|
+
print(f"DEBUG: Using different QuerySet ({type(qs)}) for {self.model}, bypassing hooks")
|
|
30
32
|
django_kwargs = {k: v for k, v in kwargs.items() if k not in ['bypass_hooks', 'bypass_validation']}
|
|
31
33
|
return qs.bulk_update(objs, fields, **django_kwargs)
|
|
32
34
|
|
|
@@ -52,6 +54,7 @@ class BulkHookManager(models.Manager):
|
|
|
52
54
|
# Check if this is our HookQuerySet or a different QuerySet
|
|
53
55
|
if hasattr(qs, 'bulk_create') and 'bypass_hooks' in inspect.signature(qs.bulk_create).parameters:
|
|
54
56
|
# Our HookQuerySet - pass all parameters
|
|
57
|
+
print(f"DEBUG: Using our HookQuerySet for {self.model}")
|
|
55
58
|
kwargs = {
|
|
56
59
|
'batch_size': batch_size,
|
|
57
60
|
'ignore_conflicts': ignore_conflicts,
|
|
@@ -62,6 +65,7 @@ class BulkHookManager(models.Manager):
|
|
|
62
65
|
return qs.bulk_create(objs, bypass_hooks=bypass_hooks, bypass_validation=bypass_validation, **kwargs)
|
|
63
66
|
else:
|
|
64
67
|
# Different QuerySet - only pass standard parameters
|
|
68
|
+
print(f"DEBUG: Using different QuerySet ({type(qs)}) for {self.model}, bypassing hooks")
|
|
65
69
|
kwargs = {
|
|
66
70
|
'batch_size': batch_size,
|
|
67
71
|
'ignore_conflicts': ignore_conflicts,
|
|
@@ -85,12 +89,14 @@ class BulkHookManager(models.Manager):
|
|
|
85
89
|
# Check if this is our HookQuerySet or a different QuerySet
|
|
86
90
|
if hasattr(qs, 'bulk_delete') and 'bypass_hooks' in inspect.signature(qs.bulk_delete).parameters:
|
|
87
91
|
# Our HookQuerySet - pass all parameters
|
|
92
|
+
print(f"DEBUG: Using our HookQuerySet for {self.model}")
|
|
88
93
|
kwargs = {
|
|
89
94
|
'batch_size': batch_size,
|
|
90
95
|
}
|
|
91
96
|
return qs.bulk_delete(objs, bypass_hooks=bypass_hooks, bypass_validation=bypass_validation, **kwargs)
|
|
92
97
|
else:
|
|
93
98
|
# Different QuerySet - only pass standard parameters
|
|
99
|
+
print(f"DEBUG: Using different QuerySet ({type(qs)}) for {self.model}, bypassing hooks")
|
|
94
100
|
kwargs = {
|
|
95
101
|
'batch_size': batch_size,
|
|
96
102
|
}
|
django_bulk_hooks/queryset.py
CHANGED
|
@@ -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
|
-
|
|
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}")
|
|
@@ -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=
|
|
6
|
+
django_bulk_hooks/engine.py,sha256=bkMlx8zCf7n36UM_aB9-KAS8beMgOGchYfvJsdZi58M,2547
|
|
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=
|
|
9
|
+
django_bulk_hooks/manager.py,sha256=ipOr2PMGycW0LpWsZ0asNRTPKVNpp3D081ibuY__cj0,5551
|
|
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=
|
|
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.
|
|
15
|
-
django_bulk_hooks-0.1.
|
|
16
|
-
django_bulk_hooks-0.1.
|
|
17
|
-
django_bulk_hooks-0.1.
|
|
14
|
+
django_bulk_hooks-0.1.165.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
|
|
15
|
+
django_bulk_hooks-0.1.165.dist-info/METADATA,sha256=6Wv5rwnHJosRAbyuT1JVGnxQ5pI9XX6V6PGYAjuToQ0,6951
|
|
16
|
+
django_bulk_hooks-0.1.165.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
17
|
+
django_bulk_hooks-0.1.165.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|