django-bulk-hooks 0.1.201__py3-none-any.whl → 0.1.202__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.
@@ -321,35 +321,34 @@ class HookQuerySetMixin:
321
321
  """
322
322
  Detect fields that were modified during BEFORE_UPDATE hooks by comparing
323
323
  new instances with their original values.
324
+ Optimized to avoid dereferencing related objects which can trigger queries.
324
325
  """
325
326
  if not original_instances:
326
327
  return set()
327
328
 
328
329
  modified_fields = set()
329
330
 
330
- # Since original_instances is now ordered to match new_instances, we can zip them directly
331
+ # Since original_instances is ordered to match new_instances, we can zip them directly
331
332
  for new_instance, original in zip(new_instances, original_instances):
332
- if new_instance.pk is None or original is None:
333
+ if new_instance is None or original is None:
333
334
  continue
334
335
 
335
- # Compare all fields to detect changes
336
- for field in new_instance._meta.fields:
337
- if field.name == "id":
336
+ # Only check local concrete fields; skip PK and many-to-many
337
+ for field in new_instance._meta.local_concrete_fields:
338
+ if field.primary_key:
338
339
  continue
339
340
 
340
- new_value = getattr(new_instance, field.name)
341
- original_value = getattr(original, field.name)
342
-
343
- # Handle different field types appropriately
344
- if field.is_relation:
345
- # For foreign keys, compare the pk values
346
- new_pk = new_value.pk if new_value else None
347
- original_pk = original_value.pk if original_value else None
348
- if new_pk != original_pk:
341
+ if getattr(field, "remote_field", None):
342
+ # ForeignKey/OneToOne: compare the raw id values via attname to avoid fetching related objects
343
+ new_id = getattr(new_instance, field.attname, None)
344
+ old_id = getattr(original, field.attname, None)
345
+ if new_id != old_id:
349
346
  modified_fields.add(field.name)
350
347
  else:
351
- # For regular fields, use direct comparison
352
- if new_value != original_value:
348
+ # Regular value fields
349
+ new_value = getattr(new_instance, field.attname if hasattr(field, "attname") else field.name)
350
+ old_value = getattr(original, field.attname if hasattr(field, "attname") else field.name)
351
+ if new_value != old_value:
353
352
  modified_fields.add(field.name)
354
353
 
355
354
  return modified_fields
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.201
3
+ Version: 0.1.202
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=xZt8iNdYF-ACz-MnKMY0co6scWINU5V5wC1lyDn844k,
9
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=J3qIJPo7-Ugj3vEwwMEr9HxMEjzlE6gVLT3HYy6abeQ,36442
12
+ django_bulk_hooks/queryset.py,sha256=NRbkJL9D_V97W76UxodMye1zaB0nJZGjMmv0SR0QLzs,36628
13
13
  django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
14
- django_bulk_hooks-0.1.201.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
- django_bulk_hooks-0.1.201.dist-info/METADATA,sha256=fHweGvMl0jrbXhvpD0KqubpJtop2agnqU6jBSxE4K8o,7418
16
- django_bulk_hooks-0.1.201.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
- django_bulk_hooks-0.1.201.dist-info/RECORD,,
14
+ django_bulk_hooks-0.1.202.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
15
+ django_bulk_hooks-0.1.202.dist-info/METADATA,sha256=sJY6iID8owgHJErIN8ZUhXNjJ7Znl1F8HedZiroE8_0,7418
16
+ django_bulk_hooks-0.1.202.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
17
+ django_bulk_hooks-0.1.202.dist-info/RECORD,,