django-bulk-hooks 0.1.72__py3-none-any.whl → 0.1.74__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/context.py +10 -0
- django_bulk_hooks/manager.py +9 -2
- django_bulk_hooks/queryset.py +18 -3
- {django_bulk_hooks-0.1.72.dist-info → django_bulk_hooks-0.1.74.dist-info}/METADATA +3 -3
- {django_bulk_hooks-0.1.72.dist-info → django_bulk_hooks-0.1.74.dist-info}/RECORD +7 -7
- {django_bulk_hooks-0.1.72.dist-info → django_bulk_hooks-0.1.74.dist-info}/WHEEL +1 -1
- {django_bulk_hooks-0.1.72.dist-info → django_bulk_hooks-0.1.74.dist-info}/LICENSE +0 -0
django_bulk_hooks/context.py
CHANGED
|
@@ -10,6 +10,16 @@ def get_hook_queue():
|
|
|
10
10
|
return _hook_context.queue
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
def is_in_bulk_operation():
|
|
14
|
+
"""Check if we're currently in a bulk operation to prevent recursion."""
|
|
15
|
+
return getattr(_hook_context, "in_bulk_operation", False)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def set_bulk_operation_flag(value):
|
|
19
|
+
"""Set the bulk operation flag to prevent recursion."""
|
|
20
|
+
_hook_context.in_bulk_operation = value
|
|
21
|
+
|
|
22
|
+
|
|
13
23
|
class HookContext:
|
|
14
24
|
def __init__(self, model_cls, metadata=None):
|
|
15
25
|
self.model_cls = model_cls
|
django_bulk_hooks/manager.py
CHANGED
|
@@ -12,7 +12,7 @@ from django_bulk_hooks.constants import (
|
|
|
12
12
|
VALIDATE_DELETE,
|
|
13
13
|
VALIDATE_UPDATE,
|
|
14
14
|
)
|
|
15
|
-
from django_bulk_hooks.context import HookContext
|
|
15
|
+
from django_bulk_hooks.context import HookContext, is_in_bulk_operation, set_bulk_operation_flag
|
|
16
16
|
from django_bulk_hooks.queryset import HookQuerySet
|
|
17
17
|
|
|
18
18
|
|
|
@@ -177,7 +177,14 @@ class BulkHookManager(models.Manager):
|
|
|
177
177
|
engine.run(model_cls, BEFORE_DELETE, objs, ctx=ctx)
|
|
178
178
|
|
|
179
179
|
pks = [obj.pk for obj in objs if obj.pk is not None]
|
|
180
|
-
|
|
180
|
+
|
|
181
|
+
# Set flag to prevent recursion during the actual deletion
|
|
182
|
+
set_bulk_operation_flag(True)
|
|
183
|
+
try:
|
|
184
|
+
# Use the custom manager - hooks won't fire again due to the flag
|
|
185
|
+
model_cls.objects.filter(pk__in=pks).delete()
|
|
186
|
+
finally:
|
|
187
|
+
set_bulk_operation_flag(False)
|
|
181
188
|
|
|
182
189
|
if not bypass_hooks:
|
|
183
190
|
engine.run(model_cls, AFTER_DELETE, objs, ctx=ctx)
|
django_bulk_hooks/queryset.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from django.db import models, transaction
|
|
2
|
+
from django_bulk_hooks.context import is_in_bulk_operation
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
class HookQuerySet(models.QuerySet):
|
|
@@ -7,7 +8,15 @@ class HookQuerySet(models.QuerySet):
|
|
|
7
8
|
objs = list(self)
|
|
8
9
|
if not objs:
|
|
9
10
|
return 0
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
# If we're already in a bulk operation, use base manager to prevent recursion
|
|
13
|
+
if is_in_bulk_operation():
|
|
14
|
+
# Use standard Django delete method on base manager
|
|
15
|
+
pks = [obj.pk for obj in objs if obj.pk is not None]
|
|
16
|
+
return self.model._base_manager.filter(pk__in=pks).delete()[0]
|
|
17
|
+
else:
|
|
18
|
+
# Normal case - use custom manager to ensure hooks fire
|
|
19
|
+
return self.model.objects.bulk_delete(objs)
|
|
11
20
|
|
|
12
21
|
@transaction.atomic
|
|
13
22
|
def update(self, **kwargs):
|
|
@@ -35,8 +44,14 @@ class HookQuerySet(models.QuerySet):
|
|
|
35
44
|
engine.run(model_cls, "before_update", instances, originals, ctx=ctx)
|
|
36
45
|
|
|
37
46
|
# Use Django's built-in update logic directly
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
# Set flag to prevent recursion during the actual update
|
|
48
|
+
from django_bulk_hooks.context import set_bulk_operation_flag
|
|
49
|
+
set_bulk_operation_flag(True)
|
|
50
|
+
try:
|
|
51
|
+
queryset = self.model.objects.filter(pk__in=pks)
|
|
52
|
+
update_count = queryset.update(**kwargs)
|
|
53
|
+
finally:
|
|
54
|
+
set_bulk_operation_flag(False)
|
|
40
55
|
|
|
41
56
|
# Run AFTER_UPDATE hooks
|
|
42
57
|
engine.run(model_cls, "after_update", instances, originals, ctx=ctx)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: django-bulk-hooks
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.74
|
|
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
|
|
6
5
|
License: MIT
|
|
7
6
|
Keywords: django,bulk,hooks
|
|
8
7
|
Author: Konrad Beck
|
|
@@ -14,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
16
15
|
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
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
django_bulk_hooks/__init__.py,sha256=uUgpnb9AWjIAcWNpCMqBcOewSnpJjJYH6cjPbQkzoNU,140
|
|
2
2
|
django_bulk_hooks/conditions.py,sha256=mTvlLcttixbXRkTSNZU5VewkPUavbXRuD2BkJbVWMkw,6041
|
|
3
3
|
django_bulk_hooks/constants.py,sha256=3x1H1fSUUNo0DZONN7GUVDuySZctTR-jtByBHmAIX5w,303
|
|
4
|
-
django_bulk_hooks/context.py,sha256=
|
|
4
|
+
django_bulk_hooks/context.py,sha256=4fUfw6eMDu2V4h9EFY7uy8uDcIL0v0Fk2YVSn6V1xMI,701
|
|
5
5
|
django_bulk_hooks/decorators.py,sha256=tckDcxtOzKCbgvS9QydgeIAWTFDEl-ch3_Q--ruEGdQ,4831
|
|
6
6
|
django_bulk_hooks/engine.py,sha256=3HbgV12JRYIy9IlygHPxZiHnFXj7EwzLyTuJNQeVIoI,1402
|
|
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=PYPq0incwM16tULpCfbR93GrGHcPtGyj4w6s0w1HCn0,7788
|
|
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=
|
|
12
|
+
django_bulk_hooks/queryset.py,sha256=vC00-LnXefpjzfz8k2qwPJ4c_Pd4baZzslzMk-ggLg4,2140
|
|
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.74.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
|
|
15
|
+
django_bulk_hooks-0.1.74.dist-info/METADATA,sha256=jlNy6giclDB1tQKvBYxcZ72WJ5TlnzlSJy3YP-GyyGs,5930
|
|
16
|
+
django_bulk_hooks-0.1.74.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
17
|
+
django_bulk_hooks-0.1.74.dist-info/RECORD,,
|
|
File without changes
|