Repository navigation
Don't mutate caller's headers dict in SendFrame.build - #206
Merged
Merged
Conversation
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.
Problem
SendFrame.buildassigned the caller's dict directly instead of copying it:So
client.send(body, destination, headers=my_headers)andtransaction.send(...)wrotedestination,content-length,content-typeandtransactionback 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-typeandtransactionare only set when non-None).SubscribeFrame.buildin the same file already copies, so this was an inconsistency rather than an intentional design.Change
SendFrame.buildnow mirrorsSubscribeFrame.build:A shallow copy is sufficient:
SendHeadersvalues arestr.The
# type: ignoreneedstypeddict-itemadded alongsideassignment— assigning adict[str, str]copy to aTypedDict-annotated name reports both codes, same as the existingSubscribeFrame.buildline.Tests
Added two regression tests in
test_send.py, one for a plainclient.sendand one fortransaction.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 skippeduv run mypy .— no issues in 50 source filesuv run ruff check --no-fix packages/— 22 pre-existingnoqa-commentsfindings in files this PR does not touch; none in the changed files