Don't crash publishing on a non-bytes message key#695
Open
wbarnha wants to merge 1 commit into
Open
Conversation
Topic.publish_message computed the sensor keysize/valsize with `len(key) if key else 0`, which raises `TypeError: object of type 'int' has no len()` when a raw, unserialized non-bytes key/value reaches it -- e.g. an int key produced via group_by/forward. This is only a sensor statistic and must never crash the actual publish. Use the existing bytes-safe `_get_len` helper (faust.types.tuples), which returns the length for bytes and 0 otherwise, consistent with how serialized key/value sizes are already computed there. Fixes #513. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #695 +/- ##
=======================================
Coverage 94.14% 94.15%
=======================================
Files 104 104
Lines 11136 11137 +1
Branches 1201 1201
=======================================
+ Hits 10484 10486 +2
+ Misses 551 550 -1
Partials 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Note: Before submitting this pull request, please review our contributing guidelines.
Description
Fixes #513.
Topic.publish_messagecomputed the sensor key/value sizes with:When a raw, unserialized non-bytes key/value reaches
publish_message— e.g. anintkey produced viagroup_by/forward—len()raisesTypeError: object of type 'int' has no len(), crashing the publish. This value only feeds a sensor statistic, so it must never break sending a message.Fix
Use the existing bytes-safe
_get_lenhelper infaust.types.tuples(len(s) if s is not None and isinstance(s, bytes) else 0) — the same helper already used there to compute serialized key/value sizes. It returns the length forbytesand0otherwise.Tests
test_publish_message__non_bytes_key_does_not_crash: aPendingMessagewith anintkey/value goes throughpublish_messagewithout raising, and the reportedkeysize/valsizeare0.TypeError: object of type 'int' has no len()atfaust/topics.py.flake8/black --check/isort --check-onlyclean.🤖 Generated with Claude Code
Generated by Claude Code