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

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.91
3
+ Version: 0.1.93
4
4
  Summary: Hook-style hooks for Django bulk operations like bulk_create and bulk_update.
5
5
  License: MIT
6
6
  Keywords: django,bulk,hooks
@@ -142,10 +142,20 @@ class HookHandler(metaclass=HookMeta):
142
142
  handler = handler_cls()
143
143
  method = getattr(handler, method_name)
144
144
 
145
+ # Inspect the method signature to determine parameter order
146
+ import inspect
147
+ sig = inspect.signature(method)
148
+ params = list(sig.parameters.keys())
149
+
150
+ # Remove 'self' from params if it exists
151
+ if params and params[0] == 'self':
152
+ params = params[1:]
153
+
154
+ # Always call with keyword arguments to make order irrelevant
145
155
  try:
146
156
  method(
147
- new_records=new_local,
148
157
  old_records=old_local,
158
+ new_records=new_local,
149
159
  **kwargs,
150
160
  )
151
161
  except Exception:
@@ -91,34 +91,27 @@ class HookModelMixin(models.Model):
91
91
  is_create = self.pk is None
92
92
  ctx = HookContext(self.__class__)
93
93
 
94
- # Use a single context manager for all hooks
94
+ # Let Django save first to handle form validation
95
+ super().save(*args, **kwargs)
96
+
97
+ # Then run our hooks with the validated data
95
98
  with patch_foreign_key_behavior():
96
99
  if is_create:
97
- # For create operations, run validation hooks first
100
+ # For create operations
98
101
  run(self.__class__, VALIDATE_CREATE, [self], ctx=ctx)
99
- # Then run BEFORE hooks
100
102
  run(self.__class__, BEFORE_CREATE, [self], ctx=ctx)
101
- # Now save
102
- super().save(*args, **kwargs)
103
- # Finally run AFTER hooks
104
103
  run(self.__class__, AFTER_CREATE, [self], ctx=ctx)
105
104
  else:
106
105
  # For update operations
107
106
  try:
108
107
  old_instance = self.__class__.objects.get(pk=self.pk)
109
- # Run validation hooks first
110
108
  run(self.__class__, VALIDATE_UPDATE, [self], [old_instance], ctx=ctx)
111
- # Then run BEFORE hooks
112
109
  run(self.__class__, BEFORE_UPDATE, [self], [old_instance], ctx=ctx)
113
- # Now save
114
- super().save(*args, **kwargs)
115
- # Finally run AFTER hooks
116
110
  run(self.__class__, AFTER_UPDATE, [self], [old_instance], ctx=ctx)
117
111
  except self.__class__.DoesNotExist:
118
112
  # If the old instance doesn't exist, treat as create
119
113
  run(self.__class__, VALIDATE_CREATE, [self], ctx=ctx)
120
114
  run(self.__class__, BEFORE_CREATE, [self], ctx=ctx)
121
- super().save(*args, **kwargs)
122
115
  run(self.__class__, AFTER_CREATE, [self], ctx=ctx)
123
116
 
124
117
  return self
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django-bulk-hooks"
3
- version = "0.1.91"
3
+ version = "0.1.93"
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"