django-bulk-hooks 0.1.72__tar.gz → 0.1.73__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.

Files changed (17) hide show
  1. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/PKG-INFO +3 -3
  2. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/context.py +10 -0
  3. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/manager.py +9 -2
  4. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/queryset.py +16 -3
  5. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/pyproject.toml +1 -1
  6. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/LICENSE +0 -0
  7. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/README.md +0 -0
  8. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/__init__.py +0 -0
  9. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/conditions.py +0 -0
  10. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/constants.py +0 -0
  11. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/decorators.py +0 -0
  12. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/engine.py +0 -0
  13. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/enums.py +0 -0
  14. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/handler.py +0 -0
  15. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/models.py +0 -0
  16. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/priority.py +0 -0
  17. {django_bulk_hooks-0.1.72 → django_bulk_hooks-0.1.73}/django_bulk_hooks/registry.py +0 -0
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.72
3
+ Version: 0.1.73
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
 
@@ -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
@@ -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
- model_cls.objects.filter(pk__in=pks).delete()
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)
@@ -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,13 @@ class HookQuerySet(models.QuerySet):
7
8
  objs = list(self)
8
9
  if not objs:
9
10
  return 0
10
- return self.model.objects.bulk_delete(objs)
11
+
12
+ # If we're already in a bulk operation, use base manager to prevent recursion
13
+ if is_in_bulk_operation():
14
+ return self.model._base_manager.bulk_delete(objs)
15
+ else:
16
+ # Normal case - use custom manager to ensure hooks fire
17
+ return self.model.objects.bulk_delete(objs)
11
18
 
12
19
  @transaction.atomic
13
20
  def update(self, **kwargs):
@@ -35,8 +42,14 @@ class HookQuerySet(models.QuerySet):
35
42
  engine.run(model_cls, "before_update", instances, originals, ctx=ctx)
36
43
 
37
44
  # Use Django's built-in update logic directly
38
- queryset = self.model._base_manager.filter(pk__in=pks)
39
- update_count = queryset.update(**kwargs)
45
+ # Set flag to prevent recursion during the actual update
46
+ from django_bulk_hooks.context import set_bulk_operation_flag
47
+ set_bulk_operation_flag(True)
48
+ try:
49
+ queryset = self.model.objects.filter(pk__in=pks)
50
+ update_count = queryset.update(**kwargs)
51
+ finally:
52
+ set_bulk_operation_flag(False)
40
53
 
41
54
  # Run AFTER_UPDATE hooks
42
55
  engine.run(model_cls, "after_update", instances, originals, ctx=ctx)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django-bulk-hooks"
3
- version = "0.1.72"
3
+ version = "0.1.73"
4
4
  description = "Hook-style hooks for Django bulk operations like bulk_create and bulk_update."
5
5
  authors = ["Konrad Beck <konrad.beck@merchantcapital.co.za>"]
6
6
  readme = "README.md"