Handle UUID task ids in key-value store backend key generation#10406
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
auvipy
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #6164
When a task id reaches the result backend as a native
uuid.UUIDinstead of a string (for example through a custom serializer that decodes UUIDs, like the rapidjson setup in the issue),_get_key_for()raisesTypeError: sequence item 1: expected a bytes-like object, UUID found.ensure_bytespasses non-string objects through unchanged, sobytes.join()blows up. The error surfaces atAsyncResult.__del__time which makes it pretty confusing to track down.This coerces UUID ids to their string form inside
_get_key_for(), which coversget_key_for_task,get_key_for_groupandget_key_for_chordin 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: