django-bulk-hooks 0.1.253__tar.gz → 0.1.254__tar.gz

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.

Files changed (17) hide show
  1. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/PKG-INFO +1 -1
  2. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/queryset.py +28 -0
  3. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/pyproject.toml +1 -1
  4. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/LICENSE +0 -0
  5. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/README.md +0 -0
  6. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/__init__.py +0 -0
  7. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/conditions.py +0 -0
  8. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/constants.py +0 -0
  9. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/context.py +0 -0
  10. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/decorators.py +0 -0
  11. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/engine.py +0 -0
  12. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/enums.py +0 -0
  13. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/handler.py +0 -0
  14. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/manager.py +0 -0
  15. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/models.py +0 -0
  16. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/priority.py +0 -0
  17. {django_bulk_hooks-0.1.253 → django_bulk_hooks-0.1.254}/django_bulk_hooks/registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.253
3
+ Version: 0.1.254
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
@@ -624,6 +624,28 @@ class HookQuerySetMixin:
624
624
  # Preserve the original updated_at timestamp
625
625
  setattr(obj, field.name, getattr(db_record, field.name))
626
626
 
627
+ # CRITICAL: Exclude auto_now fields from update_fields for existing records
628
+ # This prevents Django from including them in the ON CONFLICT DO UPDATE clause
629
+ if existing_records and update_fields:
630
+ # Identify auto_now fields that should be excluded from updates
631
+ auto_now_fields_to_exclude = set()
632
+ for field in model_cls._meta.local_fields:
633
+ if hasattr(field, "auto_now") and field.auto_now:
634
+ auto_now_fields_to_exclude.add(field.name)
635
+
636
+ # Filter out auto_now fields from update_fields for existing records
637
+ if auto_now_fields_to_exclude:
638
+ # Create a filtered version of update_fields that excludes auto_now fields
639
+ filtered_update_fields = [f for f in update_fields if f not in auto_now_fields_to_exclude]
640
+
641
+ # Store the original update_fields to restore later
642
+ ctx.original_update_fields = update_fields
643
+ ctx.auto_now_fields_excluded = auto_now_fields_to_exclude
644
+
645
+ # Use the filtered update_fields for the database operation
646
+ # This prevents Django from overwriting the timestamps during upsert
647
+ update_fields = filtered_update_fields
648
+
627
649
  # Run validation hooks on all records
628
650
  if not bypass_validation:
629
651
  engine.run(model_cls, VALIDATE_CREATE, objs, ctx=ctx)
@@ -684,6 +706,12 @@ class HookQuerySetMixin:
684
706
  # Fire AFTER hooks
685
707
  if not bypass_hooks:
686
708
  if update_conflicts and unique_fields:
709
+ # Restore original update_fields if we modified them
710
+ if hasattr(ctx, 'original_update_fields'):
711
+ update_fields = ctx.original_update_fields
712
+ delattr(ctx, 'original_update_fields')
713
+ delattr(ctx, 'auto_now_fields_excluded')
714
+
687
715
  # For upsert operations, we need to determine which records were actually created vs updated
688
716
  # Use the same logic as before to separate records
689
717
  existing_records = []
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django-bulk-hooks"
3
- version = "0.1.253"
3
+ version = "0.1.254"
4
4
  description = "Hook-style hooks for Django bulk operations like bulk_create and bulk_update."
5
5
  authors = ["Konrad Beck <konrad.beck@merchantcapital.co.za>"]
6
6
  readme = "README.md"