<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 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" checked=""> This has already been asked to the <a href="https://groups.google.com/forum/#!forum/celery-users" rel="nofollow">discussion group</a> first.</li>
<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" checked=""> 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" checked=""> 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" checked=""> 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>[] I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li>[] 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" checked=""> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li>[] I have tried reproducing the issue on more than one operating system.</li>
<li>[] I have tried reproducing the issue on more than one workers pool.</li>
<li>[] 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>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="194532272" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/3667" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/3667/hovercard" href="https://github.com/celery/celery/issues/3667">#3667</a><br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="542193436" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/5890" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/5890/hovercard" href="https://github.com/celery/celery/issues/5890">#5890</a><br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="775434141" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/6567" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/6567/hovercard" href="https://github.com/celery/celery/pull/6567">#6567</a></p>
<h4 dir="auto">Possible Duplicates</h4>
<p dir="auto">-None</p>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/celery/celery/commit/f091bab758cf430640678a16a759892bdd352800/hovercard" href="https://github.com/celery/celery/commit/f091bab758cf430640678a16a759892bdd352800"><tt>f091bab</tt></a></p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:5.0.5 (singularity) kombu:5.0.2 py:3.7.9
            billiard:3.6.3.0 redis:3.5.0
platform -&gt; system:Linux arch:64bit, ELF
            kernel version:3.10.0-1160.11.1.el7.x86_64 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://localhost:6379/0

accept_content: ['pickle']
result_serializer: 'pickle'
task_serializer: 'pickle'
worker_concurrency: 1
broker_url: 'redis://localhost:6379/0'
result_backend: 'redis://localhost:6379/0'
deprecated_settings: None"><pre class="notranslate"><code class="notranslate">software -&gt; celery:5.0.5 (singularity) kombu:5.0.2 py:3.7.9
            billiard:3.6.3.0 redis:3.5.0
platform -&gt; system:Linux arch:64bit, ELF
            kernel version:3.10.0-1160.11.1.el7.x86_64 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://localhost:6379/0

accept_content: ['pickle']
result_serializer: 'pickle'
task_serializer: 'pickle'
worker_concurrency: 1
broker_url: 'redis://localhost:6379/0'
result_backend: 'redis://localhost:6379/0'
deprecated_settings: None
</code></pre></div>
</b>
<p dir="auto">Calling <code class="notranslate">app.control.inspect().active()</code> can cause <code class="notranslate">kombu.exceptions.EncodeError: Object of type &lt;CLASSNAME&gt; is not JSON serializable</code> even when <code class="notranslate">app</code> is configured to <strong>not use JSON serialization</strong> (e.g. when pickle is configured).</p>
</summary>
<details>
<p dir="auto">
</p><p dir="auto">The issue was likely introduced by this commit:</p>
<p dir="auto"><a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/celery/celery/commit/9f0a554dc2d28c630caf9d192873d040043b7346/hovercard" href="https://github.com/celery/celery/commit/9f0a554dc2d28c630caf9d192873d040043b7346"><tt>9f0a554</tt></a></p>
<p dir="auto">It can be observed that the <code class="notranslate">Control</code> class does not pass through any of the <code class="notranslate">app</code> object's serialization configuration when constructing a <code class="notranslate">Mailbox</code> in celery/app/control.py.</p>
<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>: Unknown</li>
<li><strong>Minimal Celery Version</strong>: Unknown</li>
<li><strong>Minimal Kombu Version</strong>: Unknown</li>
<li><strong>Minimal Broker Version</strong>: Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: 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">
Before running the code below, ensure a redis server is running for Celery to connect to.
</p><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from pathlib import Path
from tempfile import NamedTemporaryFile
import threading
import time

from celery import Celery
from celery.utils.log import get_task_logger

logger = get_task_logger(__name__)

class CeleryConfig:
    task_serializer = 'pickle'
    result_serializer = 'pickle'
    accept_content = ['pickle']
    worker_concurrency = 1

app = Celery('query_active', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0', strict_typing=False)
app.config_from_object(CeleryConfig)

class SomeClass:
    def __init__(self, some_value):
        self.sleep_time = some_value

@app.task
def sleep_task(some_object: SomeClass, filepath):
    Path(filepath).touch()
    logger.info(f'Sleeping for {some_object.sleep_time}')
    time.sleep(some_object.sleep_time)
    logger.info(f'Done sleeping {some_object.sleep_time}')

if __name__ == '__main__':
    # Start a Celery Worker in a thread
    argv = ['--app=query_active', 'worker', '--loglevel=DEBUG']
    threading.Thread(target=app.worker_main, args=(argv,)).start()
    time.sleep(5)
    print('Celery should be up now')

    with NamedTemporaryFile() as f:
        # supply SomeClass, an argument that will not be JSON serializable.
        r = sleep_task.s(SomeClass(120), f.name).apply_async()
        while not Path(f.name).exists():  # wait till task is running.
            time.sleep(1)

    # Querying active causes a serialization error.
    a = app.control.inspect().active()
    print(f'Active: {a}')"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">pathlib</span> <span class="pl-k">import</span> <span class="pl-v">Path</span>
<span class="pl-k">from</span> <span class="pl-s1">tempfile</span> <span class="pl-k">import</span> <span class="pl-v">NamedTemporaryFile</span>
<span class="pl-k">import</span> <span class="pl-s1">threading</span>
<span class="pl-k">import</span> <span class="pl-s1">time</span>

<span class="pl-k">from</span> <span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>
<span class="pl-k">from</span> <span class="pl-s1">celery</span>.<span class="pl-s1">utils</span>.<span class="pl-s1">log</span> <span class="pl-k">import</span> <span class="pl-s1">get_task_logger</span>

<span class="pl-s1">logger</span> <span class="pl-c1">=</span> <span class="pl-en">get_task_logger</span>(<span class="pl-s1">__name__</span>)

<span class="pl-k">class</span> <span class="pl-v">CeleryConfig</span>:
    <span class="pl-s1">task_serializer</span> <span class="pl-c1">=</span> <span class="pl-s">'pickle'</span>
    <span class="pl-s1">result_serializer</span> <span class="pl-c1">=</span> <span class="pl-s">'pickle'</span>
    <span class="pl-s1">accept_content</span> <span class="pl-c1">=</span> [<span class="pl-s">'pickle'</span>]
    <span class="pl-s1">worker_concurrency</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(<span class="pl-s">'query_active'</span>, <span class="pl-s1">broker</span><span class="pl-c1">=</span><span class="pl-s">'redis://localhost:6379/0'</span>, <span class="pl-s1">backend</span><span class="pl-c1">=</span><span class="pl-s">'redis://localhost:6379/0'</span>, <span class="pl-s1">strict_typing</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
<span class="pl-s1">app</span>.<span class="pl-en">config_from_object</span>(<span class="pl-v">CeleryConfig</span>)

<span class="pl-k">class</span> <span class="pl-v">SomeClass</span>:
    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">some_value</span>):
        <span class="pl-s1">self</span>.<span class="pl-s1">sleep_time</span> <span class="pl-c1">=</span> <span class="pl-s1">some_value</span>

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-s1">task</span></span>
<span class="pl-k">def</span> <span class="pl-en">sleep_task</span>(<span class="pl-s1">some_object</span>: <span class="pl-v">SomeClass</span>, <span class="pl-s1">filepath</span>):
    <span class="pl-v">Path</span>(<span class="pl-s1">filepath</span>).<span class="pl-en">touch</span>()
    <span class="pl-s1">logger</span>.<span class="pl-en">info</span>(<span class="pl-s">f'Sleeping for <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">some_object</span>.<span class="pl-s1">sleep_time</span><span class="pl-kos">}</span></span>'</span>)
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-s1">some_object</span>.<span class="pl-s1">sleep_time</span>)
    <span class="pl-s1">logger</span>.<span class="pl-en">info</span>(<span class="pl-s">f'Done sleeping <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">some_object</span>.<span class="pl-s1">sleep_time</span><span class="pl-kos">}</span></span>'</span>)

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-c"># Start a Celery Worker in a thread</span>
    <span class="pl-s1">argv</span> <span class="pl-c1">=</span> [<span class="pl-s">'--app=query_active'</span>, <span class="pl-s">'worker'</span>, <span class="pl-s">'--loglevel=DEBUG'</span>]
    <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">app</span>.<span class="pl-s1">worker_main</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">argv</span>,)).<span class="pl-en">start</span>()
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">5</span>)
    <span class="pl-en">print</span>(<span class="pl-s">'Celery should be up now'</span>)

    <span class="pl-k">with</span> <span class="pl-v">NamedTemporaryFile</span>() <span class="pl-k">as</span> <span class="pl-s1">f</span>:
        <span class="pl-c"># supply SomeClass, an argument that will not be JSON serializable.</span>
        <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">sleep_task</span>.<span class="pl-en">s</span>(<span class="pl-v">SomeClass</span>(<span class="pl-c1">120</span>), <span class="pl-s1">f</span>.<span class="pl-s1">name</span>).<span class="pl-en">apply_async</span>()
        <span class="pl-k">while</span> <span class="pl-c1">not</span> <span class="pl-v">Path</span>(<span class="pl-s1">f</span>.<span class="pl-s1">name</span>).<span class="pl-en">exists</span>():  <span class="pl-c"># wait till task is running.</span>
            <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">1</span>)

    <span class="pl-c"># Querying active causes a serialization error.</span>
    <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">app</span>.<span class="pl-s1">control</span>.<span class="pl-en">inspect</span>().<span class="pl-en">active</span>()
    <span class="pl-en">print</span>(<span class="pl-s">f'Active: <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">a</span><span class="pl-kos">}</span></span>'</span>)</pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">The example runs a trivial task, then attempts to query for that task via <code class="notranslate">app.control.inspect().active()</code>.</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">Instead of receiving the task data, <code class="notranslate">app.control.inspect().active()</code> returns <code class="notranslate">None</code> and the following trace can be seen on the console logs:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
Control command error: EncodeError(TypeError('Object of type SomeClass is not JSON serializable'))
Traceback (most recent call last):
  File &quot;/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/serialization.py&quot;, line 49, in _reraise_errors
    yield
  File &quot;/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/serialization.py&quot;, line 220, in dumps
    payload = encoder(data)
  File &quot;/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/utils/json.py&quot;, line 66, in dumps
    **dict(default_kwargs, **kwargs))
  File &quot;/auto/firex/sw/python/3.7.9/lib/python3.7/json/__init__.py&quot;, line 238, in dumps
    **kw).encode(obj)
  File &quot;/auto/firex/sw/python/3.7.9/lib/python3.7/json/encoder.py&quot;, line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File &quot;/auto/firex/sw/python/3.7.9/lib/python3.7/json/encoder.py&quot;, line 257, in iterencode
    return _iterencode(o, 0)
  File &quot;/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/utils/json.py&quot;, line 55, in default
    return super().default(o)
  File &quot;/auto/firex/sw/python/3.7.9/lib/python3.7/json/encoder.py&quot;, line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type SomeClass is not JSON serializable"><pre class="notranslate"><code class="notranslate">
Control command error: EncodeError(TypeError('Object of type SomeClass is not JSON serializable'))
Traceback (most recent call last):
  File "/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/serialization.py", line 49, in _reraise_errors
    yield
  File "/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/serialization.py", line 220, in dumps
    payload = encoder(data)
  File "/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/utils/json.py", line 66, in dumps
    **dict(default_kwargs, **kwargs))
  File "/auto/firex/sw/python/3.7.9/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/auto/firex/sw/python/3.7.9/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/auto/firex/sw/python/3.7.9/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/ws/djungic-sjc/firex_ws5/lib/python3.7/site-packages/kombu/utils/json.py", line 55, in default
    return super().default(o)
  File "/auto/firex/sw/python/3.7.9/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type SomeClass is not JSON serializable
</code></pre></div></details>
<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>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h1 dir="auto">Description</h1>

<p dir="auto">I think we need to have some sort of information on what features the different backends/brokers can provide.</p>
<p dir="auto">For example, it seems that with Redis, if there is a task call, and no workers, that specific task call will never get executed. I'm guessing RabbitMQ knows to wait for workers (subscriptions) to connect, once a worker connects it will start sending previously queued task information? I'd also imagine this would be the case for AWS SQS. I haven't gotten to test SQS or RabbitMQ brokers so I can't say with certainty that this is what would happen though.</p>
<h1 dir="auto">Suggestions</h1>

<p dir="auto">Maybe a few listed differences or use cases.</p>