cardo-python-utils 0.5.dev50__py3-none-any.whl → 0.5.dev51__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.
- {cardo_python_utils-0.5.dev50.dist-info → cardo_python_utils-0.5.dev51.dist-info}/METADATA +1 -1
- {cardo_python_utils-0.5.dev50.dist-info → cardo_python_utils-0.5.dev51.dist-info}/RECORD +7 -7
- python_utils/django/README.md +5 -2
- python_utils/django/celery/tenant_aware_task.py +45 -3
- {cardo_python_utils-0.5.dev50.dist-info → cardo_python_utils-0.5.dev51.dist-info}/WHEEL +0 -0
- {cardo_python_utils-0.5.dev50.dist-info → cardo_python_utils-0.5.dev51.dist-info}/licenses/LICENSE +0 -0
- {cardo_python_utils-0.5.dev50.dist-info → cardo_python_utils-0.5.dev51.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cardo_python_utils-0.5.
|
|
1
|
+
cardo_python_utils-0.5.dev51.dist-info/licenses/LICENSE,sha256=N-YtxDy8n5A1Mo7JKKItNIlboiK_pMOZ48ojx76jo3g,1046
|
|
2
2
|
python_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
python_utils/choices.py,sha256=_sLNkSnQqhg55gGKNRsOQCJ75W6gnz8J8Q00528MEYk,2548
|
|
4
4
|
python_utils/data_structures.py,sha256=ZqkZYPy20zyGYOVhwb9qst4vF_P7X2A9z5E36rMUC6I,16820
|
|
@@ -11,7 +11,7 @@ python_utils/math.py,sha256=p_v8a9nVSe9426nR8H_SM8hOQrkzESVpCnn3gntw7TA,5603
|
|
|
11
11
|
python_utils/text.py,sha256=pw9CZeM_Lcw-6k4GyR-4D1Wix8A7F_V1u1IIZTIazW4,3792
|
|
12
12
|
python_utils/time.py,sha256=7Wei3uJ02Bk-BFRf-e1axoG418XQOhrXPvTwNZgTdnw,9614
|
|
13
13
|
python_utils/types_hinting.py,sha256=QVWzmXRgNxhvln14tEX_FbQYryuVYhjWJ0dVOnlF6G4,120
|
|
14
|
-
python_utils/django/README.md,sha256=
|
|
14
|
+
python_utils/django/README.md,sha256=ujInAhwiT87P6P0mr3TtMT_cO9-xCFihIjOOhzGi1gw,6909
|
|
15
15
|
python_utils/django/__init__.py,sha256=uXyqF-_5gZAlSIKoQkUTedAeBjnUHqh6lR6SzA1DEOM,64
|
|
16
16
|
python_utils/django/apps.py,sha256=vH2Ov8XgavTGKFLSjbH1kvuG7RWQCjeJepw6BSp2o3E,126
|
|
17
17
|
python_utils/django/oidc_settings.py,sha256=JqF-qOfW23JhmmVciN1B7ZV-KI7qrdn5VigTE7E2k_0,4367
|
|
@@ -30,7 +30,7 @@ python_utils/django/api/utils.py,sha256=ycpSnTtGcfdGP1_Hk0P2c8ZNId70xOYtjx1m0nAU
|
|
|
30
30
|
python_utils/django/auth/service.py,sha256=9gMURteyVnfjpZLyrvjAvgglfi2NPwrdia2LDVPfxBs,7475
|
|
31
31
|
python_utils/django/celery/__init__.py,sha256=eqKpBqhClH-7oK-kD1SUEpzt4Gqu7VWLWmhFUktee0A,79
|
|
32
32
|
python_utils/django/celery/tenant_aware_database_scheduler.py,sha256=Qcz8mFhfFcX8Opzb75qvuF9jxwuY8Nsn0gxIBKFaU8w,8087
|
|
33
|
-
python_utils/django/celery/tenant_aware_task.py,sha256=
|
|
33
|
+
python_utils/django/celery/tenant_aware_task.py,sha256=kjcAfAAOUAveOKaoOBe-yJLdhXIT7CMgNKOPOFKjEbQ,4065
|
|
34
34
|
python_utils/django/db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
35
|
python_utils/django/db/alias.py,sha256=sybxhZsShJdnz13hqEyYLxuaRert9zpRPPi-bAayyM4,574
|
|
36
36
|
python_utils/django/db/routers.py,sha256=Q4YAvr37wgEgL04miPKSREhzFB5LDZrXulqStbqBZeA,252
|
|
@@ -63,7 +63,7 @@ python_utils/django/storage/__init__.py,sha256=mNn2YmD7pkXhBLHMM1444BLsCMq78YdYx
|
|
|
63
63
|
python_utils/django/storage/tenant_aware_storage.py,sha256=5dDes6xLv7_R8hIBbFIzRvPL7HL9K_RM-G6LI8qUSxM,2550
|
|
64
64
|
python_utils/django/tests/__init__.py,sha256=Nkt0a7LEHyjLvuEBZ7113VjjAWJlyZlMy-H-JZ5tNcs,252
|
|
65
65
|
python_utils/django/tests/conftest.py,sha256=KozXmXUWVcDLbkVAb7Aq4sDydGLh2YZkbRa4tkA8Z6U,3167
|
|
66
|
-
cardo_python_utils-0.5.
|
|
67
|
-
cardo_python_utils-0.5.
|
|
68
|
-
cardo_python_utils-0.5.
|
|
69
|
-
cardo_python_utils-0.5.
|
|
66
|
+
cardo_python_utils-0.5.dev51.dist-info/METADATA,sha256=lEGjnoXdpwdhOZu4C70RNapEfkoTknOUCc3DaE46AKQ,3007
|
|
67
|
+
cardo_python_utils-0.5.dev51.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
68
|
+
cardo_python_utils-0.5.dev51.dist-info/top_level.txt,sha256=zAx6OfEsjJs8BEW3okSiG_j9gpkI69xWShzum6oBgKI,13
|
|
69
|
+
cardo_python_utils-0.5.dev51.dist-info/RECORD,,
|
python_utils/django/README.md
CHANGED
|
@@ -157,14 +157,17 @@ If using `django-ninja`, apart from the settings configured above, auth utils ar
|
|
|
157
157
|
|
|
158
158
|
## Atomic Transactions
|
|
159
159
|
|
|
160
|
-
Django's `transaction.atomic` uses the default database. To make it tenant-aware, use `tenant_atomic
|
|
160
|
+
Django's `transaction.atomic` uses the default database. To make it tenant-aware, use `tenant_atomic`.
|
|
161
|
+
If `transaction.on_commit` is used, make sure to pass the tenant as DB alias as well:
|
|
161
162
|
|
|
162
163
|
```python3
|
|
163
164
|
from python_utils.django.db.transaction import tenant_atomic
|
|
164
165
|
|
|
165
166
|
@tenant_atomic
|
|
166
167
|
def my_function():
|
|
167
|
-
|
|
168
|
+
# Some logic
|
|
169
|
+
|
|
170
|
+
transaction.on_commit(do_smth, using=TenantContext.get())
|
|
168
171
|
```
|
|
169
172
|
|
|
170
173
|
## Django Shell
|
|
@@ -27,8 +27,49 @@ class TenantAwareTask(TaskClass):
|
|
|
27
27
|
|
|
28
28
|
once = {"graceful": True, "unlock_before_run": False}
|
|
29
29
|
|
|
30
|
+
def apply(
|
|
31
|
+
self,
|
|
32
|
+
args=None,
|
|
33
|
+
kwargs=None,
|
|
34
|
+
link=None,
|
|
35
|
+
link_error=None,
|
|
36
|
+
task_id=None,
|
|
37
|
+
retries=None,
|
|
38
|
+
throw=None,
|
|
39
|
+
logfile=None,
|
|
40
|
+
loglevel=None,
|
|
41
|
+
headers=None,
|
|
42
|
+
**options,
|
|
43
|
+
):
|
|
44
|
+
"""Pass the tenant name from the context in the kwargs."""
|
|
45
|
+
|
|
46
|
+
if kwargs is None:
|
|
47
|
+
kwargs = {}
|
|
48
|
+
|
|
49
|
+
if TENANT_KEY not in kwargs:
|
|
50
|
+
tenant = TenantContext.get()
|
|
51
|
+
kwargs[TENANT_KEY] = tenant
|
|
52
|
+
|
|
53
|
+
return super().apply(
|
|
54
|
+
args, kwargs, link, link_error, task_id, retries, throw, logfile, loglevel, headers, **options
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def apply_async(
|
|
58
|
+
self, args=None, kwargs=None, task_id=None, producer=None, link=None, link_error=None, shadow=None, **options
|
|
59
|
+
):
|
|
60
|
+
"""Pass the tenant name from the context in the kwargs."""
|
|
61
|
+
|
|
62
|
+
if kwargs is None:
|
|
63
|
+
kwargs = {}
|
|
64
|
+
|
|
65
|
+
if TENANT_KEY not in kwargs:
|
|
66
|
+
tenant = TenantContext.get()
|
|
67
|
+
kwargs[TENANT_KEY] = tenant
|
|
68
|
+
|
|
69
|
+
return super().apply_async(args, kwargs, task_id, producer, link, link_error, shadow, **options)
|
|
70
|
+
|
|
30
71
|
def __call__(self, *args, **kwargs):
|
|
31
|
-
"""
|
|
72
|
+
"""Use the tenant name from the kwargs to update the context."""
|
|
32
73
|
|
|
33
74
|
# Only clear the lock before the task's execution if the
|
|
34
75
|
# "unlock_before_run" option is True
|
|
@@ -43,7 +84,8 @@ class TenantAwareTask(TaskClass):
|
|
|
43
84
|
return self.run(*args, **kwargs)
|
|
44
85
|
|
|
45
86
|
def after_return(self, status, retval, task_id, args, kwargs, einfo):
|
|
46
|
-
"""Clear the tenant from the
|
|
87
|
+
"""Clear the tenant from the context after the task has returned."""
|
|
88
|
+
|
|
47
89
|
TenantContext.clear()
|
|
48
90
|
super().after_return(status, retval, task_id, args, kwargs, einfo)
|
|
49
91
|
|
|
@@ -67,7 +109,7 @@ class TenantAwareTask(TaskClass):
|
|
|
67
109
|
tenant_kwarg = {TENANT_KEY: tenant}
|
|
68
110
|
task_call_args = super()._get_call_args(args, _kwargs)
|
|
69
111
|
|
|
70
|
-
# Add the tenant kwarg back to the return value
|
|
112
|
+
# Add the tenant kwarg back to the return value
|
|
71
113
|
# since this value is being used to create the key for the lock.
|
|
72
114
|
# We want to lock the task for the tenant that is running it.
|
|
73
115
|
return task_call_args | tenant_kwarg
|
|
File without changes
|
{cardo_python_utils-0.5.dev50.dist-info → cardo_python_utils-0.5.dev51.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{cardo_python_utils-0.5.dev50.dist-info → cardo_python_utils-0.5.dev51.dist-info}/top_level.txt
RENAMED
|
File without changes
|