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

@@ -54,8 +54,18 @@ class BulkHookManager(models.Manager):
54
54
  for obj in objs:
55
55
  base_obj = base_model()
56
56
  for field in base_model._meta.fields:
57
- if field.name != 'id' and hasattr(obj, field.name):
58
- setattr(base_obj, field.name, getattr(obj, field.name))
57
+ # Skip ID field
58
+ if field.name == 'id':
59
+ continue
60
+
61
+ # Safely copy field values
62
+ try:
63
+ if hasattr(obj, field.name):
64
+ setattr(base_obj, field.name, getattr(obj, field.name))
65
+ except (AttributeError, ValueError):
66
+ # Skip fields that can't be copied
67
+ continue
68
+
59
69
  base_objects.append(base_obj)
60
70
 
61
71
  return base_objects
@@ -72,10 +82,20 @@ class BulkHookManager(models.Manager):
72
82
 
73
83
  # Copy only fields specific to this model
74
84
  for field in model_cls._meta.fields:
75
- if (field.name != 'id' and
76
- field.model == model_cls and
77
- hasattr(obj, field.name)):
78
- setattr(child_obj, field.name, getattr(obj, field.name))
85
+ # Skip ID field and fields that don't belong to this model
86
+ if field.name == 'id':
87
+ continue
88
+
89
+ # Check if this field belongs to the current model
90
+ # Use a safer way to check field ownership
91
+ try:
92
+ if hasattr(field, 'model') and field.model == model_cls:
93
+ # This field belongs to the current model
94
+ if hasattr(obj, field.name):
95
+ setattr(child_obj, field.name, getattr(obj, field.name))
96
+ except AttributeError:
97
+ # Skip fields that don't have proper model reference
98
+ continue
79
99
 
80
100
  child_objects.append(child_obj)
81
101
 
@@ -100,33 +120,42 @@ class BulkHookManager(models.Manager):
100
120
  objects_by_class[obj_class].append(obj)
101
121
 
102
122
  for obj_class, class_objects in objects_by_class.items():
103
- # Check if this class has multi-table inheritance
104
- parent_models = [p for p in obj_class._meta.get_parent_list()
105
- if not p._meta.abstract]
106
-
107
- if not parent_models:
108
- # No inheritance, use standard bulk_create
109
- chunk_result = super(models.Manager, self).bulk_create(class_objects, **kwargs)
110
- result.extend(chunk_result)
111
- continue
112
-
113
- # Handle multi-table inheritance
114
- # Step 1: Bulk create base objects without hooks
115
- base_objects = self._extract_base_objects(class_objects, obj_class)
116
- created_base = super(models.Manager, self).bulk_create(base_objects, **kwargs)
117
-
118
- # Step 2: Update original objects with base IDs
119
- for obj, base_obj in zip(class_objects, created_base):
120
- obj.pk = base_obj.pk
121
- obj._state.adding = False
122
-
123
- # Step 3: Bulk create child objects without hooks
124
- child_objects = self._extract_child_objects(class_objects, obj_class)
125
- if child_objects:
126
- # Use _base_manager to avoid recursion
127
- obj_class._base_manager.bulk_create(child_objects, **kwargs)
128
-
129
- result.extend(class_objects)
123
+ try:
124
+ # Check if this class has multi-table inheritance
125
+ parent_models = [p for p in obj_class._meta.get_parent_list()
126
+ if not p._meta.abstract]
127
+
128
+ if not parent_models:
129
+ # No inheritance, use standard bulk_create
130
+ chunk_result = super(models.Manager, self).bulk_create(class_objects, **kwargs)
131
+ result.extend(chunk_result)
132
+ continue
133
+
134
+ # Handle multi-table inheritance
135
+ # Step 1: Bulk create base objects without hooks
136
+ base_objects = self._extract_base_objects(class_objects, obj_class)
137
+ created_base = super(models.Manager, self).bulk_create(base_objects, **kwargs)
138
+
139
+ # Step 2: Update original objects with base IDs
140
+ for obj, base_obj in zip(class_objects, created_base):
141
+ obj.pk = base_obj.pk
142
+ obj._state.adding = False
143
+
144
+ # Step 3: Bulk create child objects without hooks
145
+ child_objects = self._extract_child_objects(class_objects, obj_class)
146
+ if child_objects:
147
+ # Use _base_manager to avoid recursion
148
+ obj_class._base_manager.bulk_create(child_objects, **kwargs)
149
+
150
+ result.extend(class_objects)
151
+
152
+ except Exception as e:
153
+ # Add debugging information
154
+ import logging
155
+ logger = logging.getLogger(__name__)
156
+ logger.error(f"Error in _bulk_create_inherited for {obj_class}: {e}")
157
+ logger.error(f"Model fields: {[f.name for f in obj_class._meta.fields]}")
158
+ raise
130
159
 
131
160
  return result
132
161
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.104
3
+ Version: 0.1.105
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=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=5dBScf_xaXBHSCLU2sGMzmfLz-4FqvrkonpWQ-RomXg,11788
9
+ django_bulk_hooks/manager.py,sha256=Q9Oss6kWCgyL-08t3XYplLSQSLILMAX7Qv9eg7-VgKA,13147
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=iet4z-9SKhnresA4FBQbxx9rdYnoaOWbw9LUlGftlP0,1466
13
13
  django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
14
- django_bulk_hooks-0.1.104.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.104.dist-info/METADATA,sha256=QAuTwfGoLwuS5lqxxu1bcKheRAKwNrKr5dDDu4btqWU,6951
16
- django_bulk_hooks-0.1.104.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.104.dist-info/RECORD,,
14
+ django_bulk_hooks-0.1.105.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
+ django_bulk_hooks-0.1.105.dist-info/METADATA,sha256=PVNvKCg4CciKQTGbe7p4L38tsF9kuum22H7zaPu8oNs,6951
16
+ django_bulk_hooks-0.1.105.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
+ django_bulk_hooks-0.1.105.dist-info/RECORD,,