<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?q=is%3Aissue+label%3A%22Issue+Type%3A+Enhancement%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical enhancement to an existing feature.</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%22Issue+Type%3A+Enhancement%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed enhancements.</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 if the same enhancement was already implemented in the<br>
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>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h1 dir="auto">Brief Summary</h1>

<p dir="auto">Requesting that Celery's documentation include an example using a router function when calling apply_async() to determine the queue for the task. Currently, I need to route tasks to different workers on different servers with the queue name determining the server and worker on which to execute the task. My router function itself will query which workers are not busy and return the alphabetically first non-busy worker/queue (one worker per queue in my case). There are no examples of using a router function to dynamically select the queue within the documentation. Please add.</p>
<h1 dir="auto">Design</h1>
<h2 dir="auto">Architectural Considerations</h2>

<p dir="auto">None</p>
<h2 dir="auto">Proposed Behavior</h2>

<h2 dir="auto">Proposed UI/UX</h2>

<h2 dir="auto">Diagrams</h2>

<p dir="auto">N/A</p>
<h2 dir="auto">Alternatives</h2>

<p dir="auto">None</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 read the relevant section in the<br>
<a href="http://docs.celeryproject.org/en/latest/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</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/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-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%22PR+Type%3A+Bugfix%22+-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<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>:</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Celery Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Kombu Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: N/A or Unknown</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
</p><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>
<p dir="auto">When <code class="notranslate">result_extended</code> is set to <code class="notranslate">True</code>, we expect to get the task name using the <code class="notranslate">name</code> attribute.</p>
<h1 dir="auto">Actual Behavior</h1>
<p dir="auto">The <code class="notranslate">name</code> is always <code class="notranslate">None</code>, after debugging the <code class="notranslate">Context</code> object that is being passed to <code class="notranslate">BaseKeyValueStoreBackend.store_result</code> it contains the task name with the attribute <code class="notranslate">task</code> and not <code class="notranslate">task_name</code> as <code class="notranslate">BaseKeyValueStoreBackend._store_result</code> is trying to get from the request object:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if self.app.conf.find_value_for_key('extended', 'result'):
    if request:
        request_meta = {
            'name': getattr(request, 'task_name', None),
            'args': getattr(request, 'args', None),
            'kwargs': getattr(request, 'kwargs', None),
            'worker': getattr(request, 'hostname', None),
            'retries': getattr(request, 'retries', None),
            'queue': request.delivery_info.get('routing_key')
            if hasattr(request, 'delivery_info') and
            request.delivery_info else None
        }

        meta.update(request_meta)"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">app</span>.<span class="pl-s1">conf</span>.<span class="pl-en">find_value_for_key</span>(<span class="pl-s">'extended'</span>, <span class="pl-s">'result'</span>):
    <span class="pl-k">if</span> <span class="pl-s1">request</span>:
        <span class="pl-s1">request_meta</span> <span class="pl-c1">=</span> {
            <span class="pl-s">'name'</span>: <span class="pl-en">getattr</span>(<span class="pl-s1">request</span>, <span class="pl-s">'task_name'</span>, <span class="pl-c1">None</span>),
            <span class="pl-s">'args'</span>: <span class="pl-en">getattr</span>(<span class="pl-s1">request</span>, <span class="pl-s">'args'</span>, <span class="pl-c1">None</span>),
            <span class="pl-s">'kwargs'</span>: <span class="pl-en">getattr</span>(<span class="pl-s1">request</span>, <span class="pl-s">'kwargs'</span>, <span class="pl-c1">None</span>),
            <span class="pl-s">'worker'</span>: <span class="pl-en">getattr</span>(<span class="pl-s1">request</span>, <span class="pl-s">'hostname'</span>, <span class="pl-c1">None</span>),
            <span class="pl-s">'retries'</span>: <span class="pl-en">getattr</span>(<span class="pl-s1">request</span>, <span class="pl-s">'retries'</span>, <span class="pl-c1">None</span>),
            <span class="pl-s">'queue'</span>: <span class="pl-s1">request</span>.<span class="pl-s1">delivery_info</span>.<span class="pl-en">get</span>(<span class="pl-s">'routing_key'</span>)
            <span class="pl-k">if</span> <span class="pl-en">hasattr</span>(<span class="pl-s1">request</span>, <span class="pl-s">'delivery_info'</span>) <span class="pl-c1">and</span>
            <span class="pl-s1">request</span>.<span class="pl-s1">delivery_info</span> <span class="pl-k">else</span> <span class="pl-c1">None</span>
        }

        <span class="pl-s1">meta</span>.<span class="pl-en">update</span>(<span class="pl-s1">request_meta</span>)</pre></div>
<p dir="auto">Also the unit test <code class="notranslate">test_result.test_AsyncResult.test_get_request_meta</code> is using a <code class="notranslate">Context</code> object with an explicit <code class="notranslate">task_name</code> set.</p>