<p dir="auto">For a piece of code at work, we had a set of tasks that are essentially wrappers around a function. Originally each function was implemented independently. To reduce code duplication, I tried to make a higher order function that would take in the wrapped function (<code class="notranslate">ship_function</code>) and return a task that called it and did the other boilerplate code. This code is below:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def make_ship_function(ship_function, shipment_type_name, task_name):
    @task(ignore_result=True, name=__name__ + &quot;.&quot; + task_name)
    @transaction.commit_manually
    def inner(oblpn_nbr, facility_code, company_code, user = None):
        try:
            if not CWLoginContext.user and user:
                set_login_context_user(user)
                set_facility_and_company(facility_code, company_code)
            (retval, msg) = ship_function(oblpn_nbr, facility_code, company_code)
            if not retval:
                transaction.rollback()
                cwlog.error('{0}.process_shipment_ws returned false: {1}'.format(shipment_type_name, msg))
                CWLoginContext.user = None
                raise Exception(msg)
            transaction.commit()
            CWLoginContext.user = None
            return True, None
        except Exception, e:
            transaction.rollback()
            if connection.queries: cwlog.error(connection.queries[-1])
            cwlog.error('Exception in {0}.process_shipment_ws: {1}'.format(shipment_type_name, e))
            CWLoginContext.user = None
            raise e
    return inner"><pre class="notranslate"><code class="notranslate">def make_ship_function(ship_function, shipment_type_name, task_name):
    @task(ignore_result=True, name=__name__ + "." + task_name)
    @transaction.commit_manually
    def inner(oblpn_nbr, facility_code, company_code, user = None):
        try:
            if not CWLoginContext.user and user:
                set_login_context_user(user)
                set_facility_and_company(facility_code, company_code)
            (retval, msg) = ship_function(oblpn_nbr, facility_code, company_code)
            if not retval:
                transaction.rollback()
                cwlog.error('{0}.process_shipment_ws returned false: {1}'.format(shipment_type_name, msg))
                CWLoginContext.user = None
                raise Exception(msg)
            transaction.commit()
            CWLoginContext.user = None
            return True, None
        except Exception, e:
            transaction.rollback()
            if connection.queries: cwlog.error(connection.queries[-1])
            cwlog.error('Exception in {0}.process_shipment_ws: {1}'.format(shipment_type_name, e))
            CWLoginContext.user = None
            raise e
    return inner
</code></pre></div>
<p dir="auto">This code does not work properly. Even though in the task decorator, I specify the name of the task, all tasks generated by make_ship_function will all have the same name, inner. This goes against my expectations gotten from reading the docs here: <a href="http://celery.readthedocs.org/en/latest/userguide/tasks.html#names" rel="nofollow">http://celery.readthedocs.org/en/latest/userguide/tasks.html#names</a> .</p>
<h1 dir="auto">Checklist</h1>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?utf8=%E2%9C%93&amp;q=is%3Aissue+label%3A%22Category%3A+Documentation%22+">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues in this issue<br>
(If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>
<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>introduced by: PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="324688811" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/4745" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/4745/hovercard" href="https://github.com/celery/celery/pull/4745">#4745</a></li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h1 dir="auto">Description</h1>
<p dir="auto">The <a href="https://github.com/celery/celery/blob/7f9daab9d3007d2a52f7813cf12dd7fa5666c98b/docs/userguide/tasks.rst#tips-and-best-practices">user guide for tasks</a> states:  "Results can be enabled/disabled on a per-execution basis, by passing the <code class="notranslate">ignore_result</code> boolean parameter, when calling <code class="notranslate">apply_async</code> <em>or <code class="notranslate">delay</code></em>" (emphasis mine)</p>
<p dir="auto">To me, this seems to suggest that you could so something like <code class="notranslate">mytask.delay(ignore_result=True)</code>. However, that will just cause the kwarg to be passed through to the task itself, or rather, it causes an exception:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: mytask() got an unexpected keyword argument 'ignore_result'"><pre class="notranslate"><code class="notranslate">TypeError: mytask() got an unexpected keyword argument 'ignore_result'
</code></pre></div>
<p dir="auto">Looking at the <a href="https://github.com/celery/celery/blob/7f9daab9d3007d2a52f7813cf12dd7fa5666c98b/docs/userguide/calling.rst#basics">user guide on calling tasks</a>, it becomes clear that <code class="notranslate">delay</code> is just a "Shortcut to send a task message, <em>but doesn’t support execution options</em>" (emphasis mine) and hence <code class="notranslate">apply_async</code> must be used instead.</p>
<h1 dir="auto">Suggestions</h1>
<p dir="auto">Unless I'm completely misunderstanding something here, I suggest that it is made more clear in the user guide for tasks that usage of <code class="notranslate">apply_async</code> rather than <code class="notranslate">delay</code> is required to use the <code class="notranslate">ignore_result</code> kwarg.</p>