fix: isolate context dict per Confidence instance to prevent shared mutable state#115
Merged
nicklasl merged 2 commits intoMay 26, 2026
Merged
Conversation
Member
|
Looks good. Let's just make it green 👍 |
Contributor
Author
|
👍 I will fix my black formatting real quick and push back up - hold on one sec. |
Contributor
Author
|
✅ done: re-pushing to branch. confidence-sdk-python on fix/shared-mutable-context-dict [!] via v3.11.9
❯ black --check confidence --exclude="telemetry_pb2.py|_version.py" (base)
All done! ✨ 🍰 ✨
7 files would be left unchanged. |
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.
Description:
Summary
contextfrom a class-level attribute to an instance-level attribute initialized in__init__, preventing allConfidenceinstances from sharing the same dictasync_clientdefault from a mutable class-level default argument (httpx.AsyncClient()) toNone, instantiating afresh client per instance — fixing the same class of mutable-default-argument bug
Root cause
context: Dict[str, FieldType] = {}was declared at class scope, making it a single shared dict across all instances. Any call to put_context on oneConfidenceobject would silently mutate the context for every other instance in the same process. The same issue existed forasync_client, which was evaluated once at class definition time and shared.Test plan - see issue: