django-bulk-hooks 0.1.168__py3-none-any.whl → 0.1.170__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 +5 -22
- django_bulk_hooks/manager.py +54 -38
- django_bulk_hooks/queryset.py +565 -561
- {django_bulk_hooks-0.1.168.dist-info → django_bulk_hooks-0.1.170.dist-info}/METADATA +3 -3
- {django_bulk_hooks-0.1.168.dist-info → django_bulk_hooks-0.1.170.dist-info}/RECORD +7 -7
- {django_bulk_hooks-0.1.168.dist-info → django_bulk_hooks-0.1.170.dist-info}/WHEEL +1 -1
- {django_bulk_hooks-0.1.168.dist-info → django_bulk_hooks-0.1.170.dist-info}/LICENSE +0 -0
django_bulk_hooks/engine.py
CHANGED
|
@@ -11,20 +11,13 @@ def run(model_cls, event, new_records, old_records=None, ctx=None):
|
|
|
11
11
|
"""
|
|
12
12
|
Run hooks for a given model, event, and records.
|
|
13
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
14
|
if not new_records:
|
|
19
|
-
print(f"DEBUG: No new_records, skipping hooks")
|
|
20
15
|
return
|
|
21
16
|
|
|
22
17
|
# Get hooks for this model and event
|
|
23
18
|
hooks = get_hooks(model_cls, event)
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
|
|
26
20
|
if not hooks:
|
|
27
|
-
print(f"DEBUG: No hooks found for {model_cls}.{event}")
|
|
28
21
|
return
|
|
29
22
|
|
|
30
23
|
# For BEFORE_* events, run model.clean() first for validation
|
|
@@ -38,7 +31,6 @@ def run(model_cls, event, new_records, old_records=None, ctx=None):
|
|
|
38
31
|
|
|
39
32
|
# Process hooks
|
|
40
33
|
for handler_cls, method_name, condition, priority in hooks:
|
|
41
|
-
print(f"DEBUG: Processing hook: {handler_cls.__name__}.{method_name}")
|
|
42
34
|
handler_instance = handler_cls()
|
|
43
35
|
func = getattr(handler_instance, method_name)
|
|
44
36
|
|
|
@@ -50,24 +42,15 @@ def run(model_cls, event, new_records, old_records=None, ctx=None):
|
|
|
50
42
|
old_records or [None] * len(new_records),
|
|
51
43
|
strict=True,
|
|
52
44
|
):
|
|
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}")
|
|
57
45
|
if not condition or condition.check(new, original):
|
|
58
|
-
print(f"DEBUG: - condition passed, adding to process list")
|
|
59
46
|
to_process_new.append(new)
|
|
60
47
|
to_process_old.append(original)
|
|
61
|
-
else:
|
|
62
|
-
print(f"DEBUG: - condition failed, skipping")
|
|
63
48
|
|
|
64
49
|
if to_process_new:
|
|
65
|
-
print(f"DEBUG: Executing hook {handler_cls.__name__}.{method_name} with {len(to_process_new)} records")
|
|
66
50
|
try:
|
|
67
|
-
func(
|
|
68
|
-
|
|
51
|
+
func(
|
|
52
|
+
new_records=to_process_new,
|
|
53
|
+
old_records=to_process_old if any(to_process_old) else None,
|
|
54
|
+
)
|
|
69
55
|
except Exception as e:
|
|
70
|
-
print(f"DEBUG: Hook {handler_cls.__name__}.{method_name} failed with error: {e}")
|
|
71
56
|
raise
|
|
72
|
-
else:
|
|
73
|
-
print(f"DEBUG: Skipping hook {handler_cls.__name__}.{method_name} - no records to process")
|
django_bulk_hooks/manager.py
CHANGED
|
@@ -6,8 +6,6 @@ from django_bulk_hooks.queryset import HookQuerySet
|
|
|
6
6
|
class BulkHookManager(models.Manager):
|
|
7
7
|
def get_queryset(self):
|
|
8
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
9
|
return qs
|
|
12
10
|
|
|
13
11
|
def bulk_update(
|
|
@@ -18,23 +16,29 @@ class BulkHookManager(models.Manager):
|
|
|
18
16
|
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
19
17
|
"""
|
|
20
18
|
import inspect
|
|
19
|
+
|
|
21
20
|
qs = self.get_queryset()
|
|
22
|
-
|
|
23
|
-
print(f"DEBUG: bulk_update method signature: {inspect.signature(method)}")
|
|
24
|
-
print(f"DEBUG: Calling with args: objs={type(objs)}, fields={fields}, bypass_hooks={bypass_hooks}, bypass_validation={bypass_validation}, kwargs={kwargs}")
|
|
25
|
-
print(f"DEBUG: QuerySet class: {type(qs)}")
|
|
26
|
-
print(f"DEBUG: Manager type: {type(self)}")
|
|
27
|
-
print(f"DEBUG: Model: {self.model}")
|
|
28
|
-
|
|
21
|
+
|
|
29
22
|
# Check if this is our HookQuerySet or a different QuerySet
|
|
30
|
-
if
|
|
23
|
+
if (
|
|
24
|
+
hasattr(qs, "bulk_update")
|
|
25
|
+
and "bypass_hooks" in inspect.signature(qs.bulk_update).parameters
|
|
26
|
+
):
|
|
31
27
|
# Our HookQuerySet - pass all parameters
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
return qs.bulk_update(
|
|
29
|
+
objs,
|
|
30
|
+
fields,
|
|
31
|
+
bypass_hooks=bypass_hooks,
|
|
32
|
+
bypass_validation=bypass_validation,
|
|
33
|
+
**kwargs,
|
|
34
|
+
)
|
|
34
35
|
else:
|
|
35
36
|
# Different QuerySet (like queryable_properties) - only pass standard parameters
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
django_kwargs = {
|
|
38
|
+
k: v
|
|
39
|
+
for k, v in kwargs.items()
|
|
40
|
+
if k not in ["bypass_hooks", "bypass_validation"]
|
|
41
|
+
}
|
|
38
42
|
return qs.bulk_update(objs, fields, **django_kwargs)
|
|
39
43
|
|
|
40
44
|
def bulk_create(
|
|
@@ -53,30 +57,36 @@ class BulkHookManager(models.Manager):
|
|
|
53
57
|
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
54
58
|
"""
|
|
55
59
|
import inspect
|
|
60
|
+
|
|
56
61
|
qs = self.get_queryset()
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
|
|
59
63
|
# Check if this is our HookQuerySet or a different QuerySet
|
|
60
|
-
if
|
|
64
|
+
if (
|
|
65
|
+
hasattr(qs, "bulk_create")
|
|
66
|
+
and "bypass_hooks" in inspect.signature(qs.bulk_create).parameters
|
|
67
|
+
):
|
|
61
68
|
# Our HookQuerySet - pass all parameters
|
|
62
|
-
print(f"DEBUG: Using our HookQuerySet for {self.model}")
|
|
63
69
|
kwargs = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
"batch_size": batch_size,
|
|
71
|
+
"ignore_conflicts": ignore_conflicts,
|
|
72
|
+
"update_conflicts": update_conflicts,
|
|
73
|
+
"update_fields": update_fields,
|
|
74
|
+
"unique_fields": unique_fields,
|
|
69
75
|
}
|
|
70
|
-
return qs.bulk_create(
|
|
76
|
+
return qs.bulk_create(
|
|
77
|
+
objs,
|
|
78
|
+
bypass_hooks=bypass_hooks,
|
|
79
|
+
bypass_validation=bypass_validation,
|
|
80
|
+
**kwargs,
|
|
81
|
+
)
|
|
71
82
|
else:
|
|
72
83
|
# Different QuerySet - only pass standard parameters
|
|
73
|
-
print(f"DEBUG: Using different QuerySet ({type(qs)}) for {self.model}, bypassing hooks")
|
|
74
84
|
kwargs = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
"batch_size": batch_size,
|
|
86
|
+
"ignore_conflicts": ignore_conflicts,
|
|
87
|
+
"update_conflicts": update_conflicts,
|
|
88
|
+
"update_fields": update_fields,
|
|
89
|
+
"unique_fields": unique_fields,
|
|
80
90
|
}
|
|
81
91
|
return qs.bulk_create(objs, **kwargs)
|
|
82
92
|
|
|
@@ -88,22 +98,28 @@ class BulkHookManager(models.Manager):
|
|
|
88
98
|
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
89
99
|
"""
|
|
90
100
|
import inspect
|
|
101
|
+
|
|
91
102
|
qs = self.get_queryset()
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
|
|
94
104
|
# Check if this is our HookQuerySet or a different QuerySet
|
|
95
|
-
if
|
|
105
|
+
if (
|
|
106
|
+
hasattr(qs, "bulk_delete")
|
|
107
|
+
and "bypass_hooks" in inspect.signature(qs.bulk_delete).parameters
|
|
108
|
+
):
|
|
96
109
|
# Our HookQuerySet - pass all parameters
|
|
97
|
-
print(f"DEBUG: Using our HookQuerySet for {self.model}")
|
|
98
110
|
kwargs = {
|
|
99
|
-
|
|
111
|
+
"batch_size": batch_size,
|
|
100
112
|
}
|
|
101
|
-
return qs.bulk_delete(
|
|
113
|
+
return qs.bulk_delete(
|
|
114
|
+
objs,
|
|
115
|
+
bypass_hooks=bypass_hooks,
|
|
116
|
+
bypass_validation=bypass_validation,
|
|
117
|
+
**kwargs,
|
|
118
|
+
)
|
|
102
119
|
else:
|
|
103
120
|
# Different QuerySet - only pass standard parameters
|
|
104
|
-
print(f"DEBUG: Using different QuerySet ({type(qs)}) for {self.model}, bypassing hooks")
|
|
105
121
|
kwargs = {
|
|
106
|
-
|
|
122
|
+
"batch_size": batch_size,
|
|
107
123
|
}
|
|
108
124
|
return qs.bulk_delete(objs, **kwargs)
|
|
109
125
|
|