django-bulk-hooks 0.1.168__tar.gz → 0.1.169__tar.gz
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-0.1.168 → django_bulk_hooks-0.1.169}/PKG-INFO +3 -3
- django_bulk_hooks-0.1.169/django_bulk_hooks/engine.py +56 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/manager.py +54 -38
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/queryset.py +555 -561
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/pyproject.toml +1 -1
- django_bulk_hooks-0.1.168/django_bulk_hooks/engine.py +0 -73
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/LICENSE +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/README.md +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/__init__.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/conditions.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/constants.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/context.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/decorators.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/enums.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/handler.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/models.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/priority.py +0 -0
- {django_bulk_hooks-0.1.168 → django_bulk_hooks-0.1.169}/django_bulk_hooks/registry.py +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: django-bulk-hooks
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.169
|
|
4
4
|
Summary: Hook-style hooks for Django bulk operations like bulk_create and bulk_update.
|
|
5
|
+
Home-page: https://github.com/AugendLimited/django-bulk-hooks
|
|
5
6
|
License: MIT
|
|
6
7
|
Keywords: django,bulk,hooks
|
|
7
8
|
Author: Konrad Beck
|
|
@@ -13,7 +14,6 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
13
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
16
|
Requires-Dist: Django (>=4.0)
|
|
16
|
-
Project-URL: Homepage, https://github.com/AugendLimited/django-bulk-hooks
|
|
17
17
|
Project-URL: Repository, https://github.com/AugendLimited/django-bulk-hooks
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from django.core.exceptions import ValidationError
|
|
4
|
+
|
|
5
|
+
from django_bulk_hooks.registry import get_hooks
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
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
|
+
if not new_records:
|
|
15
|
+
return
|
|
16
|
+
|
|
17
|
+
# Get hooks for this model and event
|
|
18
|
+
hooks = get_hooks(model_cls, event)
|
|
19
|
+
|
|
20
|
+
if not hooks:
|
|
21
|
+
return
|
|
22
|
+
|
|
23
|
+
# For BEFORE_* events, run model.clean() first for validation
|
|
24
|
+
if event.startswith("before_"):
|
|
25
|
+
for instance in new_records:
|
|
26
|
+
try:
|
|
27
|
+
instance.clean()
|
|
28
|
+
except ValidationError as e:
|
|
29
|
+
logger.error("Validation failed for %s: %s", instance, e)
|
|
30
|
+
raise
|
|
31
|
+
|
|
32
|
+
# Process hooks
|
|
33
|
+
for handler_cls, method_name, condition, priority in hooks:
|
|
34
|
+
handler_instance = handler_cls()
|
|
35
|
+
func = getattr(handler_instance, method_name)
|
|
36
|
+
|
|
37
|
+
to_process_new = []
|
|
38
|
+
to_process_old = []
|
|
39
|
+
|
|
40
|
+
for new, original in zip(
|
|
41
|
+
new_records,
|
|
42
|
+
old_records or [None] * len(new_records),
|
|
43
|
+
strict=True,
|
|
44
|
+
):
|
|
45
|
+
if not condition or condition.check(new, original):
|
|
46
|
+
to_process_new.append(new)
|
|
47
|
+
to_process_old.append(original)
|
|
48
|
+
|
|
49
|
+
if to_process_new:
|
|
50
|
+
try:
|
|
51
|
+
func(
|
|
52
|
+
new_records=to_process_new,
|
|
53
|
+
old_records=to_process_old if any(to_process_old) else None,
|
|
54
|
+
)
|
|
55
|
+
except Exception as e:
|
|
56
|
+
raise
|
|
@@ -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
|
|