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.
github-actionsBot
changed the title
Fix input mutation in SerializationMixin.from_dict
Python: Fix input mutation in SerializationMixin.from_dict
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
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
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?
What is the impact of these changes?
What do you want reviewers to focus on?
Related Issue
Fixes #7899
Contribution Checklist