Skip to content

Commit 4eefed9

Browse files
committed
[celery#305]: Added a default callable to get_callback_function
`get_callback_function()` gets a default callback as an arg returning explicitely an empty dict. `get_callback_function()` raises an `ImproperlyConfigured` exception when the callback is not callable. --- Resolves celery#305 Fixes celery#314
1 parent 696d9d4 commit 4eefed9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

django_celery_results/backends/database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ def _store_result(
129129
self._get_extended_properties(request, traceback)
130130
)
131131

132+
# TODO: Wrap this and make some sanity checks to complain the Mapping
133+
# protocol.
132134
task_props.update(
133135
extend_task_props_callback(request, dict(task_props)))
134136

django_celery_results/settings.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
from django.conf import settings
2+
from django.core.exceptions import ImproperlyConfigured
23

34

45
def get_callback_function(settings_name, default=None):
56
"""Return the callback function for the given settings name."""
67

78
callback = getattr(settings, settings_name, None)
8-
if callback is None:
9+
if not callback:
910
return default
1011

11-
if callable(callback):
12-
return callback
12+
if not callable(callback):
13+
raise ImproperlyConfigured(f"{settings_name} must be callable.")
14+
15+
return callback
1316

1417
extend_task_props_callback = get_callback_function(
15-
"CELERY_RESULTS_EXTEND_TASK_PROPS_CALLBACK"
18+
"CELERY_RESULTS_EXTEND_TASK_PROPS_CALLBACK", dict
1619
)

0 commit comments

Comments
 (0)