django-bulk-hooks 0.1.161__tar.gz → 0.1.162__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.161 → django_bulk_hooks-0.1.162}/PKG-INFO +1 -1
- django_bulk_hooks-0.1.162/django_bulk_hooks/manager.py +124 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/pyproject.toml +1 -1
- django_bulk_hooks-0.1.161/django_bulk_hooks/manager.py +0 -91
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/LICENSE +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/README.md +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/__init__.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/conditions.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/constants.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/context.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/decorators.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/engine.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/enums.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/handler.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/models.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/priority.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/queryset.py +0 -0
- {django_bulk_hooks-0.1.161 → django_bulk_hooks-0.1.162}/django_bulk_hooks/registry.py +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
from django.db import models
|
|
2
|
+
|
|
3
|
+
from django_bulk_hooks.queryset import HookQuerySet
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BulkHookManager(models.Manager):
|
|
7
|
+
def get_queryset(self):
|
|
8
|
+
return HookQuerySet(self.model, using=self._db)
|
|
9
|
+
|
|
10
|
+
def bulk_update(
|
|
11
|
+
self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs
|
|
12
|
+
):
|
|
13
|
+
"""
|
|
14
|
+
Delegate to QuerySet's bulk_update implementation.
|
|
15
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
16
|
+
"""
|
|
17
|
+
import inspect
|
|
18
|
+
qs = self.get_queryset()
|
|
19
|
+
method = qs.bulk_update
|
|
20
|
+
print(f"DEBUG: bulk_update method signature: {inspect.signature(method)}")
|
|
21
|
+
print(f"DEBUG: Calling with args: objs={type(objs)}, fields={fields}, bypass_hooks={bypass_hooks}, bypass_validation={bypass_validation}, kwargs={kwargs}")
|
|
22
|
+
print(f"DEBUG: QuerySet class: {type(qs)}")
|
|
23
|
+
|
|
24
|
+
# Check if this is our HookQuerySet or a different QuerySet
|
|
25
|
+
if hasattr(qs, 'bulk_update') and 'bypass_hooks' in inspect.signature(qs.bulk_update).parameters:
|
|
26
|
+
# Our HookQuerySet - pass all parameters
|
|
27
|
+
return qs.bulk_update(objs, fields, bypass_hooks=bypass_hooks, bypass_validation=bypass_validation, **kwargs)
|
|
28
|
+
else:
|
|
29
|
+
# Different QuerySet (like queryable_properties) - only pass standard parameters
|
|
30
|
+
django_kwargs = {k: v for k, v in kwargs.items() if k not in ['bypass_hooks', 'bypass_validation']}
|
|
31
|
+
return qs.bulk_update(objs, fields, **django_kwargs)
|
|
32
|
+
|
|
33
|
+
def bulk_create(
|
|
34
|
+
self,
|
|
35
|
+
objs,
|
|
36
|
+
batch_size=None,
|
|
37
|
+
ignore_conflicts=False,
|
|
38
|
+
update_conflicts=False,
|
|
39
|
+
update_fields=None,
|
|
40
|
+
unique_fields=None,
|
|
41
|
+
bypass_hooks=False,
|
|
42
|
+
bypass_validation=False,
|
|
43
|
+
):
|
|
44
|
+
"""
|
|
45
|
+
Delegate to QuerySet's bulk_create implementation.
|
|
46
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
47
|
+
"""
|
|
48
|
+
import inspect
|
|
49
|
+
qs = self.get_queryset()
|
|
50
|
+
method = qs.bulk_create
|
|
51
|
+
|
|
52
|
+
# Check if this is our HookQuerySet or a different QuerySet
|
|
53
|
+
if hasattr(qs, 'bulk_create') and 'bypass_hooks' in inspect.signature(qs.bulk_create).parameters:
|
|
54
|
+
# Our HookQuerySet - pass all parameters
|
|
55
|
+
kwargs = {
|
|
56
|
+
'batch_size': batch_size,
|
|
57
|
+
'ignore_conflicts': ignore_conflicts,
|
|
58
|
+
'update_conflicts': update_conflicts,
|
|
59
|
+
'update_fields': update_fields,
|
|
60
|
+
'unique_fields': unique_fields,
|
|
61
|
+
}
|
|
62
|
+
return qs.bulk_create(objs, bypass_hooks=bypass_hooks, bypass_validation=bypass_validation, **kwargs)
|
|
63
|
+
else:
|
|
64
|
+
# Different QuerySet - only pass standard parameters
|
|
65
|
+
kwargs = {
|
|
66
|
+
'batch_size': batch_size,
|
|
67
|
+
'ignore_conflicts': ignore_conflicts,
|
|
68
|
+
'update_conflicts': update_conflicts,
|
|
69
|
+
'update_fields': update_fields,
|
|
70
|
+
'unique_fields': unique_fields,
|
|
71
|
+
}
|
|
72
|
+
return qs.bulk_create(objs, **kwargs)
|
|
73
|
+
|
|
74
|
+
def bulk_delete(
|
|
75
|
+
self, objs, batch_size=None, bypass_hooks=False, bypass_validation=False
|
|
76
|
+
):
|
|
77
|
+
"""
|
|
78
|
+
Delegate to QuerySet's bulk_delete implementation.
|
|
79
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
80
|
+
"""
|
|
81
|
+
import inspect
|
|
82
|
+
qs = self.get_queryset()
|
|
83
|
+
method = qs.bulk_delete
|
|
84
|
+
|
|
85
|
+
# Check if this is our HookQuerySet or a different QuerySet
|
|
86
|
+
if hasattr(qs, 'bulk_delete') and 'bypass_hooks' in inspect.signature(qs.bulk_delete).parameters:
|
|
87
|
+
# Our HookQuerySet - pass all parameters
|
|
88
|
+
kwargs = {
|
|
89
|
+
'batch_size': batch_size,
|
|
90
|
+
}
|
|
91
|
+
return qs.bulk_delete(objs, bypass_hooks=bypass_hooks, bypass_validation=bypass_validation, **kwargs)
|
|
92
|
+
else:
|
|
93
|
+
# Different QuerySet - only pass standard parameters
|
|
94
|
+
kwargs = {
|
|
95
|
+
'batch_size': batch_size,
|
|
96
|
+
}
|
|
97
|
+
return qs.bulk_delete(objs, **kwargs)
|
|
98
|
+
|
|
99
|
+
def update(self, **kwargs):
|
|
100
|
+
"""
|
|
101
|
+
Delegate to QuerySet's update implementation.
|
|
102
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
103
|
+
"""
|
|
104
|
+
return self.get_queryset().update(**kwargs)
|
|
105
|
+
|
|
106
|
+
def delete(self):
|
|
107
|
+
"""
|
|
108
|
+
Delegate to QuerySet's delete implementation.
|
|
109
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
110
|
+
"""
|
|
111
|
+
return self.get_queryset().delete()
|
|
112
|
+
|
|
113
|
+
def save(self, obj):
|
|
114
|
+
"""
|
|
115
|
+
Save a single object using the appropriate bulk operation.
|
|
116
|
+
"""
|
|
117
|
+
if obj.pk:
|
|
118
|
+
self.bulk_update(
|
|
119
|
+
[obj],
|
|
120
|
+
fields=[field.name for field in obj._meta.fields if field.name != "id"],
|
|
121
|
+
)
|
|
122
|
+
else:
|
|
123
|
+
self.bulk_create([obj])
|
|
124
|
+
return obj
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "django-bulk-hooks"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.162"
|
|
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"
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
from django.db import models
|
|
2
|
-
|
|
3
|
-
from django_bulk_hooks.queryset import HookQuerySet
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class BulkHookManager(models.Manager):
|
|
7
|
-
def get_queryset(self):
|
|
8
|
-
return HookQuerySet(self.model, using=self._db)
|
|
9
|
-
|
|
10
|
-
def bulk_update(
|
|
11
|
-
self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs
|
|
12
|
-
):
|
|
13
|
-
"""
|
|
14
|
-
Delegate to QuerySet's bulk_update implementation.
|
|
15
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
16
|
-
"""
|
|
17
|
-
import inspect
|
|
18
|
-
qs = self.get_queryset()
|
|
19
|
-
method = qs.bulk_update
|
|
20
|
-
print(f"DEBUG: bulk_update method signature: {inspect.signature(method)}")
|
|
21
|
-
print(f"DEBUG: Calling with args: objs={type(objs)}, fields={fields}, bypass_hooks={bypass_hooks}, bypass_validation={bypass_validation}, kwargs={kwargs}")
|
|
22
|
-
print(f"DEBUG: QuerySet class: {type(qs)}")
|
|
23
|
-
return qs.bulk_update(objs, fields, bypass_hooks, bypass_validation, **kwargs)
|
|
24
|
-
|
|
25
|
-
def bulk_create(
|
|
26
|
-
self,
|
|
27
|
-
objs,
|
|
28
|
-
batch_size=None,
|
|
29
|
-
ignore_conflicts=False,
|
|
30
|
-
update_conflicts=False,
|
|
31
|
-
update_fields=None,
|
|
32
|
-
unique_fields=None,
|
|
33
|
-
bypass_hooks=False,
|
|
34
|
-
bypass_validation=False,
|
|
35
|
-
):
|
|
36
|
-
"""
|
|
37
|
-
Delegate to QuerySet's bulk_create implementation.
|
|
38
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
39
|
-
"""
|
|
40
|
-
kwargs = {
|
|
41
|
-
'batch_size': batch_size,
|
|
42
|
-
'ignore_conflicts': ignore_conflicts,
|
|
43
|
-
'update_conflicts': update_conflicts,
|
|
44
|
-
'update_fields': update_fields,
|
|
45
|
-
'unique_fields': unique_fields,
|
|
46
|
-
}
|
|
47
|
-
return self.get_queryset().bulk_create(
|
|
48
|
-
objs,
|
|
49
|
-
bypass_hooks=bypass_hooks,
|
|
50
|
-
bypass_validation=bypass_validation,
|
|
51
|
-
**kwargs
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
def bulk_delete(
|
|
55
|
-
self, objs, batch_size=None, bypass_hooks=False, bypass_validation=False
|
|
56
|
-
):
|
|
57
|
-
"""
|
|
58
|
-
Delegate to QuerySet's bulk_delete implementation.
|
|
59
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
60
|
-
"""
|
|
61
|
-
kwargs = {
|
|
62
|
-
'batch_size': batch_size,
|
|
63
|
-
}
|
|
64
|
-
return self.get_queryset().bulk_delete(objs, bypass_hooks=bypass_hooks, bypass_validation=bypass_validation, **kwargs)
|
|
65
|
-
|
|
66
|
-
def update(self, **kwargs):
|
|
67
|
-
"""
|
|
68
|
-
Delegate to QuerySet's update implementation.
|
|
69
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
70
|
-
"""
|
|
71
|
-
return self.get_queryset().update(**kwargs)
|
|
72
|
-
|
|
73
|
-
def delete(self):
|
|
74
|
-
"""
|
|
75
|
-
Delegate to QuerySet's delete implementation.
|
|
76
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
77
|
-
"""
|
|
78
|
-
return self.get_queryset().delete()
|
|
79
|
-
|
|
80
|
-
def save(self, obj):
|
|
81
|
-
"""
|
|
82
|
-
Save a single object using the appropriate bulk operation.
|
|
83
|
-
"""
|
|
84
|
-
if obj.pk:
|
|
85
|
-
self.bulk_update(
|
|
86
|
-
[obj],
|
|
87
|
-
fields=[field.name for field in obj._meta.fields if field.name != "id"],
|
|
88
|
-
)
|
|
89
|
-
else:
|
|
90
|
-
self.bulk_create([obj])
|
|
91
|
-
return obj
|
|
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
|