Skip to content

Don't crash publishing on a non-bytes message key#695

Open
wbarnha wants to merge 1 commit into
masterfrom
claude/fix-513-nonbytes-key
Open

Don't crash publishing on a non-bytes message key#695
wbarnha wants to merge 1 commit into
masterfrom
claude/fix-513-nonbytes-key

Conversation

@wbarnha

@wbarnha wbarnha commented Jul 19, 2026

Copy link
Copy Markdown
Member

Note: Before submitting this pull request, please review our contributing guidelines.

Description

Fixes #513.

Topic.publish_message computed the sensor key/value sizes with:

keysize=len(key) if key else 0,
valsize=len(value) if value else 0,

When a raw, unserialized non-bytes key/value reaches publish_message — e.g. an int key produced via group_by/forwardlen() raises TypeError: 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_len helper in faust.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 for bytes and 0 otherwise.

Tests

  • Added test_publish_message__non_bytes_key_does_not_crash: a PendingMessage with an int key/value goes through publish_message without raising, and the reported keysize/valsize are 0.
  • Verified it catches the bug: reverting the fix makes the test fail with TypeError: object of type 'int' has no len() at faust/topics.py.
  • flake8 / black --check / isort --check-only clean.

🤖 Generated with Claude Code


Generated by Claude Code

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

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.15%. Comparing base (3073eb9) to head (0952f80).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Raw integer as key cause Topic.publish_message crash

1 participant