Skip to content

Commit 208d797

Browse files
committed
fix: small fixes
1 parent 72a8822 commit 208d797

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "cardo-python-utils"
7-
version = "0.5.5"
7+
version = "0.5.6"
88
description = "Python library enhanced with a wide range of functions for different scenarios."
99
readme = "README.rst"
1010
requires-python = ">=3.8"

python_utils/django/admin/user_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_queryset(self, request):
7171
queryset = super().get_queryset(request)
7272

7373
queryset = queryset.annotate(**{
74-
f"allowed_{entity}_count": Count(f"allowed_{entity}") for entity in self.app_entities
74+
f"allowed_{entity}_count": Count(f"allowed_{entity}", distinct=True) for entity in self.app_entities
7575
})
7676

7777
return queryset

python_utils/django/celery/tenant_aware_task.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
TaskClass = Task
1616
USE_QUEUE_ONCE = False
1717

18+
CELERY_BACKEND_CLEANUP_TASK = "celery.backend_cleanup"
19+
1820

1921
class TenantAwareTask(TaskClass):
2022
#: Enable argument checking.
@@ -46,7 +48,7 @@ def apply(
4648
if kwargs is None:
4749
kwargs = {}
4850

49-
if TENANT_KEY not in kwargs:
51+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
5052
kwargs[TENANT_KEY] = TenantContext.get()
5153

5254
return super().apply(
@@ -61,19 +63,19 @@ def apply_async(
6163
if kwargs is None:
6264
kwargs = {}
6365

64-
if TENANT_KEY not in kwargs:
66+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
6567
kwargs[TENANT_KEY] = TenantContext.get()
6668

6769
return super().apply_async(args, kwargs, task_id, producer, link, link_error, shadow, **options)
6870

6971
def s(self, *args, **kwargs):
70-
if TENANT_KEY not in kwargs:
72+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
7173
kwargs[TENANT_KEY] = TenantContext.get()
7274

7375
return self.signature(args, kwargs)
7476

7577
def si(self, *args, **kwargs):
76-
if TENANT_KEY not in kwargs:
78+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
7779
kwargs[TENANT_KEY] = TenantContext.get()
7880

7981
return self.signature(args, kwargs, immutable=True)
@@ -87,8 +89,14 @@ def __call__(self, *args, **kwargs):
8789
key = self.get_key(args, kwargs)
8890
self.once_backend.clear_lock(key)
8991

90-
if self.name != "celery.backend_cleanup":
91-
tenant = kwargs.pop(TENANT_KEY)
92+
if self.name != CELERY_BACKEND_CLEANUP_TASK:
93+
try:
94+
tenant = kwargs.pop(TENANT_KEY)
95+
except KeyError:
96+
raise RuntimeError(
97+
f"TenantAwareTask {self.name} called without tenant in kwargs. "
98+
f"Make sure to call the task with the tenant in the kwargs or use the apply/apply_async/s/si methods."
99+
)
92100
TenantContext.set(tenant)
93101

94102
return self.run(*args, **kwargs)

python_utils/django/oidc_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .tenant_context import TenantContext
1313

1414

15-
KEYCLOAK_SERVER_URL_TEMPLATE = os.getenv("KEYCLOAK_SERVER_URL_TEMPLATE", "https://keycloak.{realm}.company.com")
15+
KEYCLOAK_SERVER_URL_TEMPLATE = os.getenv("KEYCLOAK_SERVER_URL_TEMPLATE", "https://id.{realm}.company.com")
1616
KEYCLOAK_CONFIDENTIAL_CLIENT_ID = os.getenv("KEYCLOAK_CONFIDENTIAL_CLIENT_ID", None)
1717

1818
OIDC_CLIENT_AUTH_METHOD = getattr(settings, "OIDC_CLIENT_AUTH_METHOD", "client_assertion")

0 commit comments

Comments
 (0)