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.

@@ -164,11 +164,24 @@ class HookQuerySetMixin:
164
164
  output_field = field_obj
165
165
  target_name = field_name
166
166
 
167
- when_statements.append(
168
- When(
169
- pk=obj_pk, then=Value(value, output_field=output_field)
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.240
3
+ Version: 0.1.241
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
@@ -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=bi8jE8yvl2ih0M3LbzW8TZvl7JFKbgysILRXIpci6KM,42055
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.240.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.240.dist-info/METADATA,sha256=hkqwdtVcH2Te0py2ryH-RXgAJpX93e0IDFteueUBYtQ,9061
16
- django_bulk_hooks-0.1.240.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.240.dist-info/RECORD,,
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,,