django-bulk-hooks 0.1.240__py3-none-any.whl → 0.1.241__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/queryset.py +67 -4
- {django_bulk_hooks-0.1.240.dist-info → django_bulk_hooks-0.1.241.dist-info}/METADATA +1 -1
- {django_bulk_hooks-0.1.240.dist-info → django_bulk_hooks-0.1.241.dist-info}/RECORD +5 -5
- {django_bulk_hooks-0.1.240.dist-info → django_bulk_hooks-0.1.241.dist-info}/LICENSE +0 -0
- {django_bulk_hooks-0.1.240.dist-info → django_bulk_hooks-0.1.241.dist-info}/WHEEL +0 -0
django_bulk_hooks/queryset.py
CHANGED
|
@@ -164,11 +164,24 @@ class HookQuerySetMixin:
|
|
|
164
164
|
output_field = field_obj
|
|
165
165
|
target_name = field_name
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
# Special handling for Subquery values in CASE statements
|
|
168
|
+
if isinstance(value, Subquery):
|
|
169
|
+
logger.debug(f"Creating When statement with Subquery for {field_name}")
|
|
170
|
+
# Ensure the Subquery has proper output_field
|
|
171
|
+
if not hasattr(value, 'output_field') or value.output_field is None:
|
|
172
|
+
value.output_field = output_field
|
|
173
|
+
logger.debug(f"Set output_field for Subquery in When statement to {output_field}")
|
|
174
|
+
when_statements.append(
|
|
175
|
+
When(
|
|
176
|
+
pk=obj_pk, then=value
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
else:
|
|
180
|
+
when_statements.append(
|
|
181
|
+
When(
|
|
182
|
+
pk=obj_pk, then=Value(value, output_field=output_field)
|
|
183
|
+
)
|
|
170
184
|
)
|
|
171
|
-
)
|
|
172
185
|
|
|
173
186
|
if when_statements:
|
|
174
187
|
case_statements[target_name] = Case(
|
|
@@ -177,6 +190,22 @@ class HookQuerySetMixin:
|
|
|
177
190
|
|
|
178
191
|
# Merge extra CASE updates into kwargs for DB update
|
|
179
192
|
if case_statements:
|
|
193
|
+
logger.debug(f"Adding case statements to kwargs: {list(case_statements.keys())}")
|
|
194
|
+
for field_name, case_stmt in case_statements.items():
|
|
195
|
+
logger.debug(f"Case statement for {field_name}: {type(case_stmt).__name__}")
|
|
196
|
+
# Check if the case statement contains Subquery objects
|
|
197
|
+
if hasattr(case_stmt, 'get_source_expressions'):
|
|
198
|
+
source_exprs = case_stmt.get_source_expressions()
|
|
199
|
+
for expr in source_exprs:
|
|
200
|
+
if isinstance(expr, Subquery):
|
|
201
|
+
logger.debug(f"Case statement for {field_name} contains Subquery")
|
|
202
|
+
elif hasattr(expr, 'get_source_expressions'):
|
|
203
|
+
# Check nested expressions (like Value objects)
|
|
204
|
+
nested_exprs = expr.get_source_expressions()
|
|
205
|
+
for nested_expr in nested_exprs:
|
|
206
|
+
if isinstance(nested_expr, Subquery):
|
|
207
|
+
logger.debug(f"Case statement for {field_name} contains nested Subquery")
|
|
208
|
+
|
|
180
209
|
kwargs = {**kwargs, **case_statements}
|
|
181
210
|
|
|
182
211
|
# Use Django's built-in update logic directly
|
|
@@ -208,6 +237,40 @@ class HookQuerySetMixin:
|
|
|
208
237
|
else:
|
|
209
238
|
logger.debug(f"Subquery for field {key} already has output_field: {value.output_field}")
|
|
210
239
|
safe_kwargs[key] = value
|
|
240
|
+
elif hasattr(value, 'get_source_expressions') and hasattr(value, 'resolve_expression'):
|
|
241
|
+
# Handle Case statements and other complex expressions
|
|
242
|
+
logger.debug(f"Found complex expression for field {key}: {type(value).__name__}")
|
|
243
|
+
|
|
244
|
+
# Check if this expression contains any Subquery objects
|
|
245
|
+
source_expressions = value.get_source_expressions()
|
|
246
|
+
has_nested_subquery = False
|
|
247
|
+
|
|
248
|
+
for expr in source_expressions:
|
|
249
|
+
if isinstance(expr, Subquery):
|
|
250
|
+
has_nested_subquery = True
|
|
251
|
+
logger.debug(f"Found nested Subquery in {type(value).__name__}")
|
|
252
|
+
# Ensure the nested Subquery has proper output_field
|
|
253
|
+
if not hasattr(expr, 'output_field') or expr.output_field is None:
|
|
254
|
+
try:
|
|
255
|
+
field = model_cls._meta.get_field(key)
|
|
256
|
+
expr.output_field = field
|
|
257
|
+
logger.debug(f"Set output_field for nested Subquery to {field}")
|
|
258
|
+
except Exception as e:
|
|
259
|
+
logger.error(f"Failed to set output_field for nested Subquery: {e}")
|
|
260
|
+
raise
|
|
261
|
+
|
|
262
|
+
if has_nested_subquery:
|
|
263
|
+
logger.debug(f"Expression contains Subquery, ensuring proper output_field")
|
|
264
|
+
# Try to resolve the expression to ensure it's properly formatted
|
|
265
|
+
try:
|
|
266
|
+
resolved_value = value.resolve_expression(None, None)
|
|
267
|
+
safe_kwargs[key] = resolved_value
|
|
268
|
+
logger.debug(f"Successfully resolved expression for {key}")
|
|
269
|
+
except Exception as e:
|
|
270
|
+
logger.error(f"Failed to resolve expression for {key}: {e}")
|
|
271
|
+
raise
|
|
272
|
+
else:
|
|
273
|
+
safe_kwargs[key] = value
|
|
211
274
|
else:
|
|
212
275
|
logger.debug(f"Non-Subquery value for field {key}: {type(value).__name__}")
|
|
213
276
|
safe_kwargs[key] = value
|
|
@@ -9,9 +9,9 @@ django_bulk_hooks/handler.py,sha256=Bx-W6yyiciKMyy-BRxUt3CmRPCrX9_LhQgU-5LaJTjg,
|
|
|
9
9
|
django_bulk_hooks/manager.py,sha256=nfWiwU5-yAoxdnQsUMohxtyCpkV0MBv6X3wmipr9eQY,3697
|
|
10
10
|
django_bulk_hooks/models.py,sha256=exnXYVKEVbYAXhChCP8VdWTnKCnm9DiTcokEIBee1I0,4350
|
|
11
11
|
django_bulk_hooks/priority.py,sha256=HG_2D35nga68lBCZmSXTcplXrjFoRgZFRDOy4ROKonY,376
|
|
12
|
-
django_bulk_hooks/queryset.py,sha256=
|
|
12
|
+
django_bulk_hooks/queryset.py,sha256=kUmV4izYquYsvtcR3PH8TkY3PBm-Kt8c8B4HO4ck0uo,46280
|
|
13
13
|
django_bulk_hooks/registry.py,sha256=GRUTGVQEO2sdkC9OaZ9Q3U7mM-3Ix83uTyvrlTtpatw,1317
|
|
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.241.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
|
|
15
|
+
django_bulk_hooks-0.1.241.dist-info/METADATA,sha256=DUraAu1YHa04565ngESG8QnmmUwrcvrD1-4oqoOnBhY,9061
|
|
16
|
+
django_bulk_hooks-0.1.241.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
17
|
+
django_bulk_hooks-0.1.241.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|