Skip to content

Commit

Permalink
Update django.rst
Browse files Browse the repository at this point in the history
Prevent having a ValueError [1] error if we forgot the `name` parameter to `task` and `on_commit_task` if we decorate the same function twice.

[1] https://github.com/coleifer/huey/blob/master/huey/registry.py#L27
  • Loading branch information
vspiespro authored Dec 29, 2024
1 parent 327854c commit 8902282
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/django.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,17 @@ Here is the safe version:
Because we have to setup a callback to run after commit, the full functionality
of the :py:class:`TaskWrapper` is not available with tasks decorated with
:py:func:`on_commit_task`. If you anticipate needing all the TaskWrapper
methods, you can decorate the same function twice:
methods, you can decorate the same function twice by given them two different
identifier names:

.. code-block:: python
def do_work(user_id):
user = User.objects.get(pk=user_id)
...
do_work_task = task()(do_work)
do_work_on_commit = on_commit_task()(do_work)
do_work_task = task(name="do_work_task")(do_work)
do_work_on_commit = on_commit_task(name="do_work_on_commit")(do_work)
.. py:func:: on_commit_task(*args, **kwargs)
Expand Down

0 comments on commit 8902282

Please sign in to comment.