#8014·celery

Inspect raises exception for result_backend with multiple servers

Author: mpalumbo7Created Jan 19, 2023Updated Sep 12, 2026
LabelsIssue Type: Bug Report

Checklist

  • I have verified that the issue exists against the main branch of Celery.
  • This has already been asked to the discussions forum first.
  • I have read the relevant section in the contribution guide on reporting bugs.
  • I have checked the issues list for similar or identical bug reports.
  • I have checked the pull requests list for existing proposed fixes.
  • I have checked the commit log to find out if the bug was already fixed in the main branch.
  • I have included all related issues and possible duplicate issues in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

  • I have included the output of celery -A proj report in the issue. (if you are not able to do this, then at least specify the Celery version affected).
  • I have verified that the issue exists against the main branch of Celery.
  • I have included the contents of pip freeze in the issue.
  • I have included all the versions of all the external dependencies required to reproduce this bug.

Optional Debugging Information

  • I have tried reproducing the issue on more than one Python version and/or implementation.
  • I have tried reproducing the issue on more than one message broker and/or result backend.
  • I have tried reproducing the issue on more than one version of the message broker and/or result backend.
  • I have tried reproducing the issue on more than one operating system.
  • I have tried reproducing the issue on more than one workers pool.
  • I have tried reproducing the issue with autoscaling, retries, ETA/Countdown & rate limits disabled.
  • I have tried reproducing the issue after downgrading and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

Possible Duplicates

Environment & Settings

Celery version:

celery report Output:

❯ celery -A example report

software -> celery:5.2.7 (dawn-chorus) kombu:5.2.4 py:3.10.8
            billiard:3.6.4.0 py-amqp:5.1.1
platform -> system:Darwin arch:64bit
            kernel version:22.2.0 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:pyamqp results:disabled

broker_url: 'amqp://guest:********@localhost:5672//'
deprecated_settings: None

Steps to Reproduce

Required Dependencies

  • Minimal Python Version: N/A or Unknown
  • Minimal Celery Version: N/A or Unknown
  • Minimal Kombu Version: N/A or Unknown
  • Minimal Broker Version: N/A or Unknown
  • Minimal Result Backend Version: N/A or Unknown
  • Minimal OS and/or Kernel Version: N/A or Unknown
  • Minimal Broker Client Version: N/A or Unknown
  • Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

❯ pip freeze                               
amqp==5.1.1
billiard==3.6.4.0
celery==5.2.7
click==8.1.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
kombu==5.2.4
prompt-toolkit==3.0.36
pytz==2022.7.1
six==1.16.0
vine==5.0.0
wcwidth==0.2.6

Other Dependencies

N/A

Minimally Reproducible Test Case

This is pretty straightforward. It's been raised in other issues (#4059) but never explained clearly. I took the following right from the docs and it doesn't work.

TL;DR - The inspect command tries to sanitize URLs but raises an exception when they are not exactly a URL.

core.py

python
from celery import Celery

app = Celery('core')
app.config_from_object('celeryconfig', force=True)

@app.task
def add(x, y):
    return x + y

celeryconfig.py

python
## Broker settings.
broker_url = 'amqp://guest:guest@localhost:5672//'

## Using the database to store task state and results.
result_backend = 'cache+memcached://127.0.0.1:11211/'

Expected Behavior

When you run celery -A core report everything works fine.

❯ celery -A core report

software -> celery:5.2.7 (dawn-chorus) kombu:5.2.4 py:3.10.8
            billiard:3.6.4.0 py-amqp:5.1.1
platform -> system:Darwin arch:64bit
            kernel version:22.2.0 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:amqp results:cache+memcached://127.0.0.1:11211/

broker_url: 'amqp://guest:********@localhost:5672//'
result_backend: 'cache+memcached://127.0.0.1:11211/'
deprecated_settings: None

Notice the result_backend is printed just fine.

Actual Behavior

When you change the result_backend to multiple servers (see docs) it crashes.

celeryconfig.py

python
## Broker settings
broker_url = 'amqp://guest:guest@localhost:5672//'

## Backend settings
result_backend = """
    cache+memcached://172.19.26.240:11211;172.19.26.242:11211/
""".strip()

And now run celery -A core report:

❯ celery -A core report
Traceback (most recent call last):
  File "/Users/thor/.venvs/celery_bug/bin/celery", line 8, in <module>
    sys.exit(main())
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/celery/__main__.py", line 15, in main
    sys.exit(_main())
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/celery/bin/celery.py", line 217, in main
    return celery(auto_envvar_prefix="CELERY")
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/celery/bin/celery.py", line 162, in report
    ctx.obj.echo(app.bugreport())
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/celery/app/base.py", line 952, in bugreport
    return bugreport(self)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/celery/app/utils.py", line 373, in bugreport
    results=maybe_sanitize_url(app.conf.result_backend or 'disabled'),
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/kombu/utils/url.py", line 110, in maybe_sanitize_url
    return sanitize_url(url, mask)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/kombu/utils/url.py", line 103, in sanitize_url
    return as_url(*_parse_url(url), sanitize=True, mask=mask)
  File "/Users/thor/.venvs/celery_bug/lib/python3.10/site-packages/kombu/utils/url.py", line 68, in url_to_parts
    parts.port,
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/parse.py", line 178, in port
    raise ValueError(message) from None
ValueError: Port could not be cast to integer value as '11211;172.19.26.242:11211'

This is pretty easy to reproduce at the REPL:

python
>>> from kombu.utils.url import sanitize_url
>>> sanitize_url("cache+memcached://172.19.26.240:11211;172.19.26.242:11211/")

    ValueError: Port could not be cast to integer value as '11211;172.19.26.242:11211'