django-bulk-hooks 0.1.71__py3-none-any.whl → 0.1.72__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.

@@ -1,4 +1,5 @@
1
1
  from django.db import models, transaction
2
+
2
3
  from django_bulk_hooks import engine
3
4
  from django_bulk_hooks.constants import (
4
5
  AFTER_CREATE,
@@ -8,8 +9,8 @@ from django_bulk_hooks.constants import (
8
9
  BEFORE_DELETE,
9
10
  BEFORE_UPDATE,
10
11
  VALIDATE_CREATE,
11
- VALIDATE_UPDATE,
12
12
  VALIDATE_DELETE,
13
+ VALIDATE_UPDATE,
13
14
  )
14
15
  from django_bulk_hooks.context import HookContext
15
16
  from django_bulk_hooks.queryset import HookQuerySet
@@ -22,7 +23,9 @@ class BulkHookManager(models.Manager):
22
23
  return HookQuerySet(self.model, using=self._db)
23
24
 
24
25
  @transaction.atomic
25
- def bulk_update(self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs):
26
+ def bulk_update(
27
+ self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs
28
+ ):
26
29
  if not objs:
27
30
  return []
28
31
 
@@ -34,13 +37,27 @@ class BulkHookManager(models.Manager):
34
37
  )
35
38
 
36
39
  if not bypass_hooks:
37
- originals = list(model_cls.objects.filter(pk__in=[obj.pk for obj in objs]))
40
+ # Check if we're already in a hook context (recursive call)
41
+ # If so, refetch the current database state like Salesforce does
42
+ import threading
43
+
44
+ if hasattr(threading.current_thread(), "_hook_context"):
45
+ # We're in a recursive call - refetch current DB state
46
+ originals = list(
47
+ model_cls.objects.filter(pk__in=[obj.pk for obj in objs])
48
+ )
49
+ else:
50
+ # First call - use the passed originals
51
+ originals = list(
52
+ model_cls.objects.filter(pk__in=[obj.pk for obj in objs])
53
+ )
54
+
38
55
  ctx = HookContext(model_cls)
39
-
56
+
40
57
  # Run validation hooks first
41
58
  if not bypass_validation:
42
59
  engine.run(model_cls, VALIDATE_UPDATE, objs, originals, ctx=ctx)
43
-
60
+
44
61
  # Then run business logic hooks
45
62
  engine.run(model_cls, BEFORE_UPDATE, objs, originals, ctx=ctx)
46
63
 
@@ -118,11 +135,11 @@ class BulkHookManager(models.Manager):
118
135
 
119
136
  if not bypass_hooks:
120
137
  ctx = HookContext(model_cls)
121
-
138
+
122
139
  # Run validation hooks first
123
140
  if not bypass_validation:
124
141
  engine.run(model_cls, VALIDATE_CREATE, objs, ctx=ctx)
125
-
142
+
126
143
  # Then run business logic hooks
127
144
  engine.run(model_cls, BEFORE_CREATE, objs, ctx=ctx)
128
145
 
@@ -136,7 +153,9 @@ class BulkHookManager(models.Manager):
136
153
  return result
137
154
 
138
155
  @transaction.atomic
139
- def bulk_delete(self, objs, batch_size=None, bypass_hooks=False, bypass_validation=False):
156
+ def bulk_delete(
157
+ self, objs, batch_size=None, bypass_hooks=False, bypass_validation=False
158
+ ):
140
159
  if not objs:
141
160
  return []
142
161
 
@@ -153,7 +172,7 @@ class BulkHookManager(models.Manager):
153
172
  # Run validation hooks first
154
173
  if not bypass_validation:
155
174
  engine.run(model_cls, VALIDATE_DELETE, objs, ctx=ctx)
156
-
175
+
157
176
  # Then run business logic hooks
158
177
  engine.run(model_cls, BEFORE_DELETE, objs, ctx=ctx)
159
178
 
@@ -1,7 +1,8 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.1
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.71
3
+ Version: 0.1.72
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
 
@@ -6,12 +6,12 @@ django_bulk_hooks/decorators.py,sha256=tckDcxtOzKCbgvS9QydgeIAWTFDEl-ch3_Q--ruEG
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=8ifRsHFJZXViTHdKbVWFd35MF5xHvGqu9UttgsLrkVU,6911
9
+ django_bulk_hooks/manager.py,sha256=2_ycq4efNoAUP-pP_2JlZZwo1bs8_NxXe8CG3489H78,7465
10
10
  django_bulk_hooks/models.py,sha256=7RG7GrOdHXFjGVPV4FPRZVNMIHHW-hMCi6hn9LH_hVI,3331
11
11
  django_bulk_hooks/priority.py,sha256=HG_2D35nga68lBCZmSXTcplXrjFoRgZFRDOy4ROKonY,376
12
12
  django_bulk_hooks/queryset.py,sha256=nmVZ6cqkveSiBz_L4cRT-3u-mkcjkGQNJLhza8SSdKc,1398
13
13
  django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
14
- django_bulk_hooks-0.1.71.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.71.dist-info/METADATA,sha256=Ys-lGAZiQXE46EtkP8t_0DxNbqwtJPhisRDa2LWe-HA,5930
16
- django_bulk_hooks-0.1.71.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.71.dist-info/RECORD,,
14
+ django_bulk_hooks-0.1.72.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
+ django_bulk_hooks-0.1.72.dist-info/METADATA,sha256=CXElKfEZhyk3Rta_0IorEXwRbI81bkKR-DNsChpUlTY,5918
16
+ django_bulk_hooks-0.1.72.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
+ django_bulk_hooks-0.1.72.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any