django-bulk-hooks 0.1.189__tar.gz → 0.1.190__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.189 → django_bulk_hooks-0.1.190}/PKG-INFO +1 -1
  2. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/manager.py +29 -11
  3. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/queryset.py +15 -4
  4. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/pyproject.toml +1 -1
  5. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/LICENSE +0 -0
  6. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/README.md +0 -0
  7. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/__init__.py +0 -0
  8. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/conditions.py +0 -0
  9. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/constants.py +0 -0
  10. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/context.py +0 -0
  11. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/decorators.py +0 -0
  12. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/engine.py +0 -0
  13. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/enums.py +0 -0
  14. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/handler.py +0 -0
  15. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/models.py +0 -0
  16. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/priority.py +0 -0
  17. {django_bulk_hooks-0.1.189 → django_bulk_hooks-0.1.190}/django_bulk_hooks/registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.189
3
+ Version: 0.1.190
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
@@ -12,18 +12,36 @@ def inject_bulk_hook_behavior(queryset):
12
12
  queryset: Any Django QuerySet instance
13
13
 
14
14
  Returns:
15
- The same queryset instance with bulk hook functionality added
15
+ A new queryset instance with bulk hook functionality added
16
16
  """
17
- if not isinstance(queryset, HookQuerySetMixin):
18
- # Create a new class that inherits from both HookQuerySetMixin and the queryset's class
19
- HookedQuerySetClass = type(
20
- "HookedQuerySet",
21
- (HookQuerySetMixin, queryset.__class__),
22
- {}
23
- )
24
- # Change the instance's class to the new hybrid class
25
- queryset.__class__ = HookedQuerySetClass
26
- return queryset
17
+ if isinstance(queryset, HookQuerySetMixin):
18
+ # Already has hook functionality, return as-is
19
+ return queryset
20
+
21
+ # Create a new class that inherits from both HookQuerySetMixin and the queryset's class
22
+ HookedQuerySetClass = type(
23
+ "HookedQuerySet",
24
+ (HookQuerySetMixin, queryset.__class__),
25
+ {
26
+ '__module__': 'django_bulk_hooks.queryset',
27
+ '__doc__': f'Dynamically created queryset with bulk hook functionality for {queryset.__class__.__name__}'
28
+ }
29
+ )
30
+
31
+ # Create a new instance with the same parameters
32
+ new_queryset = HookedQuerySetClass(
33
+ model=queryset.model,
34
+ query=queryset.query,
35
+ using=queryset._db,
36
+ hints=queryset._hints
37
+ )
38
+
39
+ # Copy any additional attributes that might be important
40
+ for attr, value in queryset.__dict__.items():
41
+ if not hasattr(new_queryset, attr):
42
+ setattr(new_queryset, attr, value)
43
+
44
+ return new_queryset
27
45
 
28
46
 
29
47
  class BulkHookManager(models.Manager):
@@ -642,10 +642,16 @@ class HookQuerySetMixin:
642
642
  # If objects have pk set but are not loaded from DB, use those PKs
643
643
  root_pks = []
644
644
  for obj in batch:
645
- if obj.pk is not None:
646
- root_pks.append(obj.pk)
645
+ # Check both pk and id attributes
646
+ pk_value = getattr(obj, 'pk', None)
647
+ if pk_value is None:
648
+ pk_value = getattr(obj, 'id', None)
649
+
650
+ if pk_value is not None:
651
+ root_pks.append(pk_value)
652
+ print(f"Found PK {pk_value} for object {obj}")
647
653
  else:
648
- print(f"WARNING: Object {obj} has no primary key")
654
+ print(f"WARNING: Object {obj} has no primary key (pk={getattr(obj, 'pk', None)}, id={getattr(obj, 'id', None)})")
649
655
  continue
650
656
 
651
657
  print(f"Root PKs to update: {root_pks}")
@@ -708,7 +714,12 @@ class HookQuerySetMixin:
708
714
 
709
715
  print(f"Building CASE statement for field: {field_name}")
710
716
  for pk, obj in zip(pks, batch):
711
- if obj.pk is None:
717
+ # Check both pk and id attributes for the object
718
+ obj_pk = getattr(obj, 'pk', None)
719
+ if obj_pk is None:
720
+ obj_pk = getattr(obj, 'id', None)
721
+
722
+ if obj_pk is None:
712
723
  continue
713
724
  value = getattr(obj, field_name)
714
725
  print(f" PK {pk}: {field_name} = {value}")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django-bulk-hooks"
3
- version = "0.1.189"
3
+ version = "0.1.190"
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"