Python: Discard unsafe Content fields during deepcopy - #7903
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits intoAug 27, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Content.__deepcopy__ to discard unsafe shallow-copy fields while preserving isolation.
Changes:
- Replace unsafe fields with
Noneand log warnings. - Update deepcopy and response-coalescing tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
python/packages/core/agent_framework/_types.py |
Implements safe field discarding during deepcopy. |
python/packages/core/tests/core/test_types.py |
Updates tests for the new behavior. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
@microsoft-github-policy-service agree |
Sweetteabittersugar
force-pushed
the
codex/issue-7851-content-deepcopy
branch
from
August 27, 2026 09:44
3239add to
5dd1f56
Compare
Sweetteabittersugar
marked this pull request as ready for review
August 27, 2026 09:45
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Eduard van Valkenburg (eavanvalkenburg)
enabled auto-merge
August 27, 2026 13:56
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Aug 27, 2026
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.
Motivation & Context
Content.__deepcopy__currently keeps fields listed in_SHALLOW_COPY_FIELDSby reference. This creates a partially deep-copied object that can still share mutable provider SDK state with the original. The issue proposes discarding designated unsafe data and logging the loss so deepcopy retains isolation without failing on opaque provider objects.Description & Review Guide
NoneContent._SHALLOW_COPY_FIELDSvalue toNonein the clone and emit a warning.Contentfields normally.Contentobjects no longer share provider-specific raw state with their source.raw_representationafter aContentdeepcopy will receiveNone; the original object remains unchanged.SerializationMixinbehavior is intentionally unchanged because Python: [Bug]: ShouldContent.__deepcopy__preserve unsafe fields #7851 is scoped toContent._SHALLOW_COPY_FIELDSshould always be discarded, rather than copied on a best-effort basis.Related Issue
Fixes #7851
This is an alternative to #7898. That PR first attempts to deepcopy marked values and discards them only on failure, and it also changes
SerializationMixin. This PR applies the issue's narrowerContentcontract directly: every non-Nonedesignated unsafe value is discarded. Besides avoiding copies of values already classified as unsafe, this approach cannot leave partial entries in the shared deepcopy memo after a failed best-effort copy.Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.