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

@@ -3,37 +3,24 @@ from django.db import models
3
3
  from django_bulk_hooks.queryset import HookQuerySet, HookQuerySetMixin
4
4
 
5
5
 
6
- def inject_bulk_hook_behavior(queryset):
7
- """
8
- Dynamically inject bulk hook behavior into any queryset.
9
- This follows the industry-standard pattern for cooperative queryset extensions.
10
-
11
- Args:
12
- queryset: Any Django QuerySet instance
13
-
14
- Returns:
15
- The same queryset instance with bulk hook functionality added
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
27
-
28
-
29
6
  class BulkHookManager(models.Manager):
30
7
  def get_queryset(self):
31
8
  # Use super().get_queryset() to let Django and MRO build the queryset
32
9
  # This ensures cooperation with other managers
33
10
  base_queryset = super().get_queryset()
34
11
 
35
- # Inject our bulk hook behavior into the queryset
36
- return inject_bulk_hook_behavior(base_queryset)
12
+ # If the base queryset already has hook functionality, return it as-is
13
+ if isinstance(base_queryset, HookQuerySetMixin):
14
+ return base_queryset
15
+
16
+ # Otherwise, create a new HookQuerySet with the same parameters
17
+ # This is much simpler and avoids dynamic class creation issues
18
+ return HookQuerySet(
19
+ model=base_queryset.model,
20
+ query=base_queryset.query,
21
+ using=base_queryset._db,
22
+ hints=base_queryset._hints
23
+ )
37
24
 
38
25
  def bulk_create(
39
26
  self,
@@ -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
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.189
3
+ Version: 0.1.191
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
@@ -6,12 +6,12 @@ django_bulk_hooks/decorators.py,sha256=WD7Jn7QAvY8F4wOsYlIpjoM9-FdHXSKB7hH9ot-lk
6
6
  django_bulk_hooks/engine.py,sha256=nA5PU9msk_Ju5Gf_sTd7GqPscuTxEW5itCDAoSScYGI,1645
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=kQtCYven1jy4Ix8By84Ppql_YmOCIrroMsx0sF8DMC0,4090
9
+ django_bulk_hooks/manager.py,sha256=nfWiwU5-yAoxdnQsUMohxtyCpkV0MBv6X3wmipr9eQY,3697
10
10
  django_bulk_hooks/models.py,sha256=7fnx5xd4HWXfLVlFhhiRzR92JRWFEuxgk6aSWLEsyJg,3996
11
11
  django_bulk_hooks/priority.py,sha256=HG_2D35nga68lBCZmSXTcplXrjFoRgZFRDOy4ROKonY,376
12
- django_bulk_hooks/queryset.py,sha256=EfjQsMxQZALvklgXxaocYSJcYi6Ci2cPqHZRA8yU7bg,31080
12
+ django_bulk_hooks/queryset.py,sha256=eaeSmYW3VrJjhom_wXKzndmEkrKm-xaG0qflYhKSgIA,31663
13
13
  django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
14
- django_bulk_hooks-0.1.189.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.189.dist-info/METADATA,sha256=8216ShJl-ccuV5WsJfrGxDvC0BG8a7zm3I4iQh2HiLI,7418
16
- django_bulk_hooks-0.1.189.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.189.dist-info/RECORD,,
14
+ django_bulk_hooks-0.1.191.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
+ django_bulk_hooks-0.1.191.dist-info/METADATA,sha256=mRfmlZrQZOUaD8dQ50605aqAzIOF8-Z7fxzjl0z_oyU,7418
16
+ django_bulk_hooks-0.1.191.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
+ django_bulk_hooks-0.1.191.dist-info/RECORD,,