Skip to content

Fix properties dict mutation in testing.create_context#104

Merged
gmr merged 1 commit into
mainfrom
fix/testing-properties-mutation
Jul 6, 2026
Merged

Fix properties dict mutation in testing.create_context#104
gmr merged 1 commit into
mainfrom
fix/testing-properties-mutation

Conversation

@gmr

@gmr gmr commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a bug where testing.AsyncTestCase.create_context mutated the caller-supplied properties dict.

Problem / Solution

Testing

Full suite green (209 tests) + ruff clean. New test in tests/test_testing.py reproduces the mutation (verified failing before, passing after).

Closes #98

Summary by CodeRabbit

  • Bug Fixes
    • Improved context creation so provided property dictionaries are no longer modified in place.
    • Reusing the same properties input across multiple context creations now keeps the original values intact, while each context still gets the correct content type.

AsyncTestCase.create_context used `properties = properties or {}`,
which keeps the caller's object, then wrote defaults into it via
setdefault(). A caller reusing the same non-empty dict across
create_context/process_message calls got stale content_type, type,
and timestamp on later calls, since setdefault sees the previously
written keys and refuses to overwrite them.

Copy the dict first (`dict(properties) if properties else {}`) so the
caller's object is never mutated and each call applies its own
defaults.

Closes #98

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 74b58a9d-cdf1-43b3-8d3f-f3b8a0b99ac6

📥 Commits

Reviewing files that changed from the base of the PR and between 401dd78 and a9a7353.

📒 Files selected for processing (2)
  • rejected/testing.py
  • tests/test_testing.py

📝 Walkthrough

Walkthrough

AsyncTestCase.create_context in rejected/testing.py now copies the caller-supplied properties dict into a new dict before applying setdefault mutations, preventing mutation of the caller's original object. A corresponding test verifies this behavior.

Changes

Properties Dict Mutation Fix

Layer / File(s) Summary
Copy properties before mutation
rejected/testing.py
create_context now constructs a new dict from properties when provided, instead of reusing the caller's mapping directly, before applying setdefault defaults.
Regression test for dict mutation
tests/test_testing.py
Adds TestPropertiesNotMutated which reuses the same properties dict across two create_context calls and asserts the original dict is unchanged while each context reflects its own content_type.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

A dict once shared got mutated by mistake,
Two contexts fought over the same content_type at stake.
Now copies are made, safe and new,
The caller's props stay pristine and true.
Hop hop hooray, the bug's undone! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: preventing properties dict mutation in create_context.
Linked Issues check ✅ Passed The code copies the caller-supplied properties dict and the regression test confirms the mutation bug is fixed.
Out of Scope Changes check ✅ Passed The PR stays focused on the reported bug and its test coverage, with no unrelated changes apparent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@gmr

gmr commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@gmr gmr merged commit 88596bd into main Jul 6, 2026
6 checks passed
@gmr gmr deleted the fix/testing-properties-mutation branch July 6, 2026 17:29
gmr added a commit that referenced this pull request Jul 6, 2026
Bumps version from 4.0.0a3 to 4.0.0b1. This beta lands 32 verified
bug fixes across the message-processing lifecycle, daemon signal
handling, codecs, and metrics/exception handling (PRs #100-#104).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

testing.AsyncTestCase.create_context mutates the caller-supplied properties dict

1 participant