Skip to content

AsyncResult.forget() using couchdb backend throws TypeError: a bytes-like object is required, not 'str' #9864

@temaxuck

Description

@temaxuck

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).
  • I have tried to reproduce the issue with pytest-celery and added the reproduction script below.

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

  • None

Environment & Settings

Celery version: 5.4.0 (opalescent)

celery report Output:

software -> celery:5.4.0 (opalescent) kombu:5.5.4 py:3.11.2
            billiard:4.2.1 py-amqp:5.3.1
platform -> system:Linux arch:64bit, ELF
            kernel version:6.1.0-37-amd64 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:amqp results:couchdb://admin:**@localhost:5984/documents_tasks

broker_url: 'amqp://admin:********@localhost:5672/'
result_backend: 'couchdb://admin:********@localhost:5984/documents_tasks'
include: ['tasks']
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:

amqp==5.3.1
async-timeout==5.0.1
billiard==4.2.1
celery==5.4.0
certifi==2025.8.3
charset-normalizer==3.4.3
click==8.2.1
click-didyoumean==0.3.1
click-plugins==1.1.1.2
click-repl==0.3.0
idna==3.10
kombu==5.5.4
packaging==25.0
prompt_toolkit==3.0.51
pycouchdb==1.14.2
PyJWT==2.10.1
python-dateutil==2.9.0.post0
redis==5.3.1
requests==2.32.4
six==1.17.0
tzdata==2025.2
urllib3==2.5.0
vine==5.1.0
wcwidth==0.2.13

Other Dependencies

Details

N/A

Minimally Reproducible Test Case

Details

# tasks.py
from celery import Celery

app = Celery("tasks", broker=f"amqp://...",  backend=f"couchdb://...")

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

# main.py
from tasks import add

promise = add.delay(6, 9)
promise.get()
promise.forget()

Expected Behavior

Result is deleted from the result backend.

Actual Behavior

TypeError: a bytes-like object is required, not 'str' rises:

Details

Traceback (most recent call last):
  File "/home/temax/Probe/python/celery/main.py", line 35, in <module>
    promise.forget()
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/celery/result.py", line 140, in forget
    self.backend.forget(self.id)
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/celery/backends/base.py", line 549, in forget
    self._forget(task_id)
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/celery/backends/base.py", line 959, in _forget
    self.delete(self.get_key_for_task(task_id))
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/celery/backends/couchdb.py", line 99, in delete
    self.connection.delete(key)
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/pycouchdb/client.py", line 286, in delete
    resource = self.resource(*_id_to_path(_id))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/pycouchdb/resource.py", line 52, in __call__
    base_url = utils.urljoin(self.base_url, *path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/pycouchdb/utils.py", line 86, in urljoin
    return reduce(_join, path, base)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/temax/Probe/python/celery/.venv/lib/python3.11/site-packages/pycouchdb/utils.py", line 55, in _join
    parts = [head.rstrip(URLSPLITTER), tail.lstrip(URLSPLITTER)]
                                       ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'str'

The error is caused by this method:

def delete(self, key):

Adding key = bytes_to_str(key) before self.connection.delete(key) fixes the error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions