django-bulk-hooks 0.1.104__py3-none-any.whl → 0.1.106__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.
- django_bulk_hooks/manager.py +71 -37
- {django_bulk_hooks-0.1.104.dist-info → django_bulk_hooks-0.1.106.dist-info}/METADATA +1 -1
- {django_bulk_hooks-0.1.104.dist-info → django_bulk_hooks-0.1.106.dist-info}/RECORD +5 -5
- {django_bulk_hooks-0.1.104.dist-info → django_bulk_hooks-0.1.106.dist-info}/LICENSE +0 -0
- {django_bulk_hooks-0.1.104.dist-info → django_bulk_hooks-0.1.106.dist-info}/WHEEL +0 -0
django_bulk_hooks/manager.py
CHANGED
|
@@ -26,10 +26,15 @@ class BulkHookManager(models.Manager):
|
|
|
26
26
|
"""
|
|
27
27
|
Check if this model uses multi-table inheritance.
|
|
28
28
|
"""
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if not model_cls._meta.parents:
|
|
30
|
+
return False
|
|
31
|
+
|
|
32
|
+
# Check if any parent is not abstract
|
|
33
|
+
for parent_model in model_cls._meta.parents.keys():
|
|
34
|
+
if not parent_model._meta.abstract:
|
|
35
|
+
return True
|
|
36
|
+
|
|
37
|
+
return False
|
|
33
38
|
|
|
34
39
|
def _get_base_model(self, model_cls):
|
|
35
40
|
"""
|
|
@@ -54,8 +59,18 @@ class BulkHookManager(models.Manager):
|
|
|
54
59
|
for obj in objs:
|
|
55
60
|
base_obj = base_model()
|
|
56
61
|
for field in base_model._meta.fields:
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
# Skip ID field
|
|
63
|
+
if field.name == 'id':
|
|
64
|
+
continue
|
|
65
|
+
|
|
66
|
+
# Safely copy field values
|
|
67
|
+
try:
|
|
68
|
+
if hasattr(obj, field.name):
|
|
69
|
+
setattr(base_obj, field.name, getattr(obj, field.name))
|
|
70
|
+
except (AttributeError, ValueError):
|
|
71
|
+
# Skip fields that can't be copied
|
|
72
|
+
continue
|
|
73
|
+
|
|
59
74
|
base_objects.append(base_obj)
|
|
60
75
|
|
|
61
76
|
return base_objects
|
|
@@ -72,10 +87,20 @@ class BulkHookManager(models.Manager):
|
|
|
72
87
|
|
|
73
88
|
# Copy only fields specific to this model
|
|
74
89
|
for field in model_cls._meta.fields:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
# Skip ID field and fields that don't belong to this model
|
|
91
|
+
if field.name == 'id':
|
|
92
|
+
continue
|
|
93
|
+
|
|
94
|
+
# Check if this field belongs to the current model
|
|
95
|
+
# Use a safer way to check field ownership
|
|
96
|
+
try:
|
|
97
|
+
if hasattr(field, 'model') and field.model == model_cls:
|
|
98
|
+
# This field belongs to the current model
|
|
99
|
+
if hasattr(obj, field.name):
|
|
100
|
+
setattr(child_obj, field.name, getattr(obj, field.name))
|
|
101
|
+
except AttributeError:
|
|
102
|
+
# Skip fields that don't have proper model reference
|
|
103
|
+
continue
|
|
79
104
|
|
|
80
105
|
child_objects.append(child_obj)
|
|
81
106
|
|
|
@@ -100,33 +125,42 @@ class BulkHookManager(models.Manager):
|
|
|
100
125
|
objects_by_class[obj_class].append(obj)
|
|
101
126
|
|
|
102
127
|
for obj_class, class_objects in objects_by_class.items():
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
obj
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
try:
|
|
129
|
+
# Check if this class has multi-table inheritance
|
|
130
|
+
parent_models = [p for p in obj_class._meta.get_parent_list()
|
|
131
|
+
if not p._meta.abstract]
|
|
132
|
+
|
|
133
|
+
if not parent_models:
|
|
134
|
+
# No inheritance, use standard bulk_create
|
|
135
|
+
chunk_result = super(models.Manager, self).bulk_create(class_objects, **kwargs)
|
|
136
|
+
result.extend(chunk_result)
|
|
137
|
+
continue
|
|
138
|
+
|
|
139
|
+
# Handle multi-table inheritance
|
|
140
|
+
# Step 1: Bulk create base objects without hooks
|
|
141
|
+
base_objects = self._extract_base_objects(class_objects, obj_class)
|
|
142
|
+
created_base = super(models.Manager, self).bulk_create(base_objects, **kwargs)
|
|
143
|
+
|
|
144
|
+
# Step 2: Update original objects with base IDs
|
|
145
|
+
for obj, base_obj in zip(class_objects, created_base):
|
|
146
|
+
obj.pk = base_obj.pk
|
|
147
|
+
obj._state.adding = False
|
|
148
|
+
|
|
149
|
+
# Step 3: Bulk create child objects without hooks
|
|
150
|
+
child_objects = self._extract_child_objects(class_objects, obj_class)
|
|
151
|
+
if child_objects:
|
|
152
|
+
# Use _base_manager to avoid recursion
|
|
153
|
+
obj_class._base_manager.bulk_create(child_objects, **kwargs)
|
|
154
|
+
|
|
155
|
+
result.extend(class_objects)
|
|
156
|
+
|
|
157
|
+
except Exception as e:
|
|
158
|
+
# Add debugging information
|
|
159
|
+
import logging
|
|
160
|
+
logger = logging.getLogger(__name__)
|
|
161
|
+
logger.error(f"Error in _bulk_create_inherited for {obj_class}: {e}")
|
|
162
|
+
logger.error(f"Model fields: {[f.name for f in obj_class._meta.fields]}")
|
|
163
|
+
raise
|
|
130
164
|
|
|
131
165
|
return result
|
|
132
166
|
|
|
@@ -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=
|
|
9
|
+
django_bulk_hooks/manager.py,sha256=0Q7WEomcHcVFFJNX4jfR7hDzXFwZtZaAQgtw0R7eHDQ,13280
|
|
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.
|
|
15
|
-
django_bulk_hooks-0.1.
|
|
16
|
-
django_bulk_hooks-0.1.
|
|
17
|
-
django_bulk_hooks-0.1.
|
|
14
|
+
django_bulk_hooks-0.1.106.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
|
|
15
|
+
django_bulk_hooks-0.1.106.dist-info/METADATA,sha256=yvzLRWz77WeeMo8eSNRPhdpn-nu2jCqi4xjTS9J4JKk,6951
|
|
16
|
+
django_bulk_hooks-0.1.106.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
17
|
+
django_bulk_hooks-0.1.106.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|