Skip to content

Commit

Permalink
[celery#305]: Added a default callable to get_callback_function
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
diegocastrum committed Aug 15, 2022
1 parent 696d9d4 commit 4eefed9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions django_celery_results/backends/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def _store_result(
self._get_extended_properties(request, traceback)
)

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

Expand Down
11 changes: 7 additions & 4 deletions django_celery_results/settings.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured


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

callback = getattr(settings, settings_name, None)
if callback is None:
if not callback:
return default

if callable(callback):
return callback
if not callable(callback):
raise ImproperlyConfigured(f"{settings_name} must be callable.")

return callback

extend_task_props_callback = get_callback_function(
"CELERY_RESULTS_EXTEND_TASK_PROPS_CALLBACK"
"CELERY_RESULTS_EXTEND_TASK_PROPS_CALLBACK", dict
)

0 comments on commit 4eefed9

Please sign in to comment.