django-bulk-hooks 0.1.278__tar.gz → 0.1.280__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.
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/PKG-INFO +1 -1
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/queryset.py +61 -7
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/pyproject.toml +1 -1
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/LICENSE +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/README.md +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/__init__.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/conditions.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/constants.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/context.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/decorators.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/engine.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/enums.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/handler.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/manager.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/models.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/priority.py +0 -0
- {django_bulk_hooks-0.1.278 → django_bulk_hooks-0.1.280}/django_bulk_hooks/registry.py +0 -0
|
@@ -1718,7 +1718,21 @@ class HookQuerySetMixin:
|
|
|
1718
1718
|
engine.run(model_class, BEFORE_UPDATE, [parent_obj], ctx=ctx)
|
|
1719
1719
|
|
|
1720
1720
|
# Update the existing parent object
|
|
1721
|
-
|
|
1721
|
+
# Filter update_fields to only include fields that exist in the parent model
|
|
1722
|
+
parent_update_fields = kwargs.get("update_fields")
|
|
1723
|
+
if parent_update_fields:
|
|
1724
|
+
# Only include fields that exist in the parent model
|
|
1725
|
+
parent_model_fields = {
|
|
1726
|
+
field.name for field in model_class._meta.local_fields
|
|
1727
|
+
}
|
|
1728
|
+
filtered_update_fields = [
|
|
1729
|
+
field
|
|
1730
|
+
for field in parent_update_fields
|
|
1731
|
+
if field in parent_model_fields
|
|
1732
|
+
]
|
|
1733
|
+
parent_obj.save(update_fields=filtered_update_fields)
|
|
1734
|
+
else:
|
|
1735
|
+
parent_obj.save()
|
|
1722
1736
|
|
|
1723
1737
|
# Fire AFTER_UPDATE hooks for parent
|
|
1724
1738
|
if not bypass_hooks:
|
|
@@ -1759,16 +1773,47 @@ class HookQuerySetMixin:
|
|
|
1759
1773
|
current_parent = parent_obj
|
|
1760
1774
|
parent_objects_map[id(obj)] = parent_instances
|
|
1761
1775
|
|
|
1762
|
-
# Step 2:
|
|
1776
|
+
# Step 2: Handle child objects - create new ones and update existing ones
|
|
1763
1777
|
child_model = inheritance_chain[-1]
|
|
1764
1778
|
all_child_objects = []
|
|
1779
|
+
existing_child_objects = []
|
|
1780
|
+
|
|
1765
1781
|
for obj in batch:
|
|
1766
|
-
|
|
1767
|
-
obj, child_model, parent_objects_map.get(id(obj), {})
|
|
1768
|
-
)
|
|
1769
|
-
all_child_objects.append(child_obj)
|
|
1782
|
+
is_existing_record = obj in existing_records_list
|
|
1770
1783
|
|
|
1771
|
-
|
|
1784
|
+
if is_existing_record:
|
|
1785
|
+
# For existing records, update the child object
|
|
1786
|
+
child_obj = self._create_child_instance(
|
|
1787
|
+
obj, child_model, parent_objects_map.get(id(obj), {})
|
|
1788
|
+
)
|
|
1789
|
+
existing_child_objects.append(child_obj)
|
|
1790
|
+
else:
|
|
1791
|
+
# For new records, create the child object
|
|
1792
|
+
child_obj = self._create_child_instance(
|
|
1793
|
+
obj, child_model, parent_objects_map.get(id(obj), {})
|
|
1794
|
+
)
|
|
1795
|
+
all_child_objects.append(child_obj)
|
|
1796
|
+
|
|
1797
|
+
# Step 2.5: Update existing child objects
|
|
1798
|
+
if existing_child_objects:
|
|
1799
|
+
for child_obj in existing_child_objects:
|
|
1800
|
+
# Filter update_fields to only include fields that exist in the child model
|
|
1801
|
+
child_update_fields = kwargs.get("update_fields")
|
|
1802
|
+
if child_update_fields:
|
|
1803
|
+
# Only include fields that exist in the child model
|
|
1804
|
+
child_model_fields = {
|
|
1805
|
+
field.name for field in child_model._meta.local_fields
|
|
1806
|
+
}
|
|
1807
|
+
filtered_child_update_fields = [
|
|
1808
|
+
field
|
|
1809
|
+
for field in child_update_fields
|
|
1810
|
+
if field in child_model_fields
|
|
1811
|
+
]
|
|
1812
|
+
child_obj.save(update_fields=filtered_child_update_fields)
|
|
1813
|
+
else:
|
|
1814
|
+
child_obj.save()
|
|
1815
|
+
|
|
1816
|
+
# Step 2.6: Use Django's internal bulk_create infrastructure for new child objects
|
|
1772
1817
|
if all_child_objects:
|
|
1773
1818
|
# Get the base manager's queryset
|
|
1774
1819
|
base_qs = child_model._base_manager.using(self.db)
|
|
@@ -1830,12 +1875,21 @@ class HookQuerySetMixin:
|
|
|
1830
1875
|
|
|
1831
1876
|
# Step 3: Update original objects with generated PKs and state
|
|
1832
1877
|
pk_field_name = child_model._meta.pk.name
|
|
1878
|
+
|
|
1879
|
+
# Handle new objects
|
|
1833
1880
|
for orig_obj, child_obj in zip(batch, all_child_objects):
|
|
1834
1881
|
child_pk = getattr(child_obj, pk_field_name)
|
|
1835
1882
|
setattr(orig_obj, pk_field_name, child_pk)
|
|
1836
1883
|
orig_obj._state.adding = False
|
|
1837
1884
|
orig_obj._state.db = self.db
|
|
1838
1885
|
|
|
1886
|
+
# Handle existing objects (they already have PKs, just update state)
|
|
1887
|
+
for orig_obj in batch:
|
|
1888
|
+
is_existing_record = orig_obj in existing_records_list
|
|
1889
|
+
if is_existing_record:
|
|
1890
|
+
orig_obj._state.adding = False
|
|
1891
|
+
orig_obj._state.db = self.db
|
|
1892
|
+
|
|
1839
1893
|
return batch
|
|
1840
1894
|
|
|
1841
1895
|
def _create_parent_instance(self, source_obj, parent_model, current_parent):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "django-bulk-hooks"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.280"
|
|
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"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|