Skip to content

Handle UUID task ids in key-value store backend key generation#10406

Merged
auvipy merged 2 commits into
celery:mainfrom
MahinAnowar:fix/backend-key-uuid-task-id
Jul 15, 2026
Merged

Handle UUID task ids in key-value store backend key generation#10406
auvipy merged 2 commits into
celery:mainfrom
MahinAnowar:fix/backend-key-uuid-task-id

Conversation

@MahinAnowar

Copy link
Copy Markdown
Contributor

Description

Fixes #6164

When a task id reaches the result backend as a native uuid.UUID instead of a string (for example through a custom serializer that decodes UUIDs, like the rapidjson setup in the issue), _get_key_for() raises TypeError: sequence item 1: expected a bytes-like object, UUID found. ensure_bytes passes non-string objects through unchanged, so bytes.join() blows up. The error surfaces at AsyncResult.__del__ time which makes it pretty confusing to track down.

This coerces UUID ids to their string form inside _get_key_for(), which covers get_key_for_task, get_key_for_group and get_key_for_chord in one place.

Also added the failing tests that were asked for in the issue thread. On current main all three raise the exact TypeError from the report, with the fix they pass:

t/unit/backends/test_base.py::test_KeyValueStoreBackend::test_get_key_for_task_uuid_task_id PASSED
t/unit/backends/test_base.py::test_KeyValueStoreBackend::test_get_key_for_group_uuid_group_id PASSED
t/unit/backends/test_base.py::test_KeyValueStoreBackend::test_get_key_for_chord_uuid_group_id PASSED

MahinAnowar and others added 2 commits July 11, 2026 15:58
A task id can reach the result backend as a native uuid.UUID, e.g. via
a custom serializer that decodes UUIDs, and then _get_key_for() raises
TypeError because ensure_bytes passes non-string objects through
unchanged and bytes.join() rejects them. Coerce UUID ids to their
string form before building the key.

Fixes celery#6164
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.42%. Comparing base (a094d2a) to head (243522c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10406   +/-   ##
=======================================
  Coverage   88.42%   88.42%           
=======================================
  Files         153      153           
  Lines       19793    19796    +3     
  Branches     2298     2299    +1     
=======================================
+ Hits        17502    17505    +3     
  Misses       1994     1994           
  Partials      297      297           
Flag Coverage Δ
unittests 88.40% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy auvipy added this to the 5.7.0 milestone Jul 15, 2026
@auvipy
auvipy merged commit 6e0d683 into celery:main Jul 15, 2026
339 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError raised at AsyncResult destruction time

2 participants