Skip to content

Avoid mutating typed dictionaries during restore#461

Merged
essweine merged 1 commit into
mainfrom
fix/dictionary-restore-no-mutation
Apr 28, 2026
Merged

Avoid mutating typed dictionaries during restore#461
essweine merged 1 commit into
mainfrom
fix/dictionary-restore-no-mutation

Conversation

@jbirddog
Copy link
Copy Markdown
Contributor

Summary

This change fixes a side effect in DictionaryConverter.restore() when restoring typed dictionaries.

Previously, if the input dict contained a typename, restore() removed that key from the original input via
pop(). That meant callers could get their source data mutated during deserialization.

This update changes restore() to:

  • read typename without mutating the original input
  • restore from a shallow copy of the typed dictionary
  • keep the existing recursive restore behavior for nested values
  • add a regression test covering the non-mutation behavior

It also includes a small cleanup in restore() for JSON primitive values and common container types.

Why

Deserializer helpers should not mutate caller-owned input data. That behavior is surprising, can make debugging
harder, and can break reuse of the same serialized structure across multiple restore calls or assertions.

Test Plan

  • Ran:
    • uv run python -m unittest -v tests.SpiffWorkflow.bpmn.serializer.DictionaryConverterTest

@essweine
Copy link
Copy Markdown
Contributor

I disagree that removing the typename is a big deal, but again, whatever. At least this is a neutral change rather that the other crap I've felt forced to merge.


from functools import partial

_JSON_PRIMITIVE_TYPES = {str, int, float, bool, type(None)}
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.

i've seen these _UNDERSCORE_CONSTANTS elsewhere from agents. is there some method to this madness? it's being used in the same file?

@essweine essweine merged commit 3e7526b into main Apr 28, 2026
6 checks passed
@essweine essweine deleted the fix/dictionary-restore-no-mutation branch April 28, 2026 14:28
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.

3 participants