#37206: Drop tasks' is_module_level_function in favor of the established
deconstructable paradigm
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):
* cc: Jake Howard (added)
Comment:
Sorry Johannes, can you clarify what changes you are expecting here in
terms of what would be supported?
I think this is saying you would like support to be added for something
like
{{{#!python
from django.utils.deconstruct import deconstructible
@deconstructible
class NoopCallable:
def __init__(self, value):
self.value = value
def __call__(self, *args, **kwargs):
pass
my_task = task(foo=5, bar=600)(NoopCallable(value=123))
}}}
And that the check in `BaseTaskBackend.validate_task` might become:
{{{#!python
if not is_module_level_function(task.func) and not hasattr(task.func,
"deconstruct"):
raise InvalidTask(
"Task function must be a module-level function or deconstructible
callable."
)
}}}
Is that right? Can you add an example to illustrate in case I have
misunderstood?
--
Ticket URL: <
https://code.djangoproject.com/ticket/37206#comment:1>