Skip to content

Don't mutate caller's headers dict in SendFrame.build - #206

Merged
lesnik512 merged 1 commit into
mainfrom
fix/send-frame-headers-copy
Sep 17, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
fix/send-frame-headers-copy

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Problem

SendFrame.build assigned the caller's dict directly instead of copying it:

all_headers: SendHeaders = headers or {}
all_headers["destination"] = destination

So client.send(body, destination, headers=my_headers) and transaction.send(...) wrote destination, content-length, content-type and transaction back into the dict the caller passed in. A caller reusing one headers dict across sends — in a loop, or as a module-level default — silently accumulates another destination's headers, and a later send to a different destination carries leftovers if any key is not overwritten on that path (content-type and transaction are only set when non-None).

SubscribeFrame.build in the same file already copies, so this was an inconsistency rather than an intentional design.

Change

SendFrame.build now mirrors SubscribeFrame.build:

all_headers: SendHeaders = headers.copy() if headers else {}

A shallow copy is sufficient: SendHeaders values are str.

The # type: ignore needs typeddict-item added alongside assignment — assigning a dict[str, str] copy to a TypedDict-annotated name reports both codes, same as the existing SubscribeFrame.build line.

Tests

Added two regression tests in test_send.py, one for a plain client.send and one for transaction.send, each asserting the caller's dict is unchanged after the call. Both fail before the fix and pass after.

Verification

  • uv run pytest packages/stompman --ignore=packages/stompman/test_stompman/test_integration.py — 292 passed, 1 skipped
  • uv run mypy . — no issues in 50 source files
  • uv run ruff check --no-fix packages/ — 22 pre-existing noqa-comments findings in files this PR does not touch; none in the changed files

@lesnik512
lesnik512 merged commit 028d6a2 into main Sep 17, 2026
6 checks passed
@lesnik512
lesnik512 deleted the fix/send-frame-headers-copy branch September 17, 2026 14:03
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.

1 participant