Skip to content

Python: Fix input mutation in SerializationMixin.from_dict - #7901

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
Namraa310806:fix/serialization-input-mutation
Aug 27, 2026
Merged

Python: Fix input mutation in SerializationMixin.from_dict#7901
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
Namraa310806:fix/serialization-input-mutation

Conversation

@Namraa310806

Copy link
Copy Markdown
Contributor

Motivation & Context

SerializationMixin.from_dict() can unexpectedly mutate nested dictionaries in the caller-provided input when dictionary-shaped dependencies are merged during deserialization.

The method creates a shallow copy of the input dictionary, so nested dictionaries remain shared with the original input. The subsequent in-place .update() operations therefore modify the caller's input.

This can cause unexpected state to persist when the same serialized specification is reused across multiple from_dict() calls. In particular, dependency data injected during one reconstruction can leak into subsequent reconstructions.

This change fixes that behavior while preserving the existing dictionary dependency merge semantics and dependency precedence.

Description & Review Guide

  • What are the major changes?

    • Replaced the two in-place dictionary .update() operations in SerializationMixin.from_dict() with non-mutating dictionary merges.
    • Added regression tests covering both dictionary dependency merge paths.
    • Added coverage to verify that repeated from_dict() calls using the same input do not leak dependency state.
    • Added coverage to verify that existing dependency override/merge behavior is preserved.
  • What is the impact of these changes?

    • The caller-provided input dictionary is no longer modified by dictionary dependency merging.
    • Existing dictionary merge behavior remains unchanged, including dependency values overriding conflicting keys.
    • No public API or serialization format is changed.
    • This is a focused bug fix with no intended impact on unrelated serialization or dependency-injection behavior.
  • What do you want reviewers to focus on?

    • Whether the non-mutating dictionary merge is the appropriate way to preserve the existing dependency merge semantics.
    • Whether the regression tests adequately cover both dependency merge paths and prevent cross-call state leakage.

Related Issue

Fixes #7899

Contribution Checklist

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 27, 2026
@github-actions github-actions Bot changed the title Fix input mutation in SerializationMixin.from_dict Python: Fix input mutation in SerializationMixin.from_dict Aug 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _serialization.py1761193%356–357, 562, 637, 640, 683–684, 688–689, 691, 693
TOTAL48227448390% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9764 36 💤 0 ❌ 0 🔥 2m 41s ⏱️

Merged via the queue into microsoft:main with commit dc77142 Aug 27, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: SerializationMixin.from_dict() mutates caller input when merging dictionary dependencies

3 participants