Repository navigation
fix: preserve non-string dict keys in pipeline snapshot serialization - #13732
Merged
davidsbatista merged 4 commits intoNov 17, 2026
Merged
Conversation
Dicts with non-string keys serialized by _serialize_value_with_schema were
written through the properties/data mappings, whose keys json.dump
stringifies: resuming a pipeline from a snapshot file turned int keys into
strings and merged keys that stringify alike (e.g. {1: "a", "1": "b"}
came back as {"1": "b"}).
Dicts with any non-string key are now serialized as an explicit list of
key/value entries, each key with its own schema, and the deserializer
rebuilds the dict from those entries. Dicts with only string keys keep the
historical properties envelope, and snapshots created by earlier Haystack
versions still load. The field-by-field fallback path of
_serialize_with_field_fallback uses the same encoding, and a dict key that
cannot be serialized now degrades like a failing value instead of breaking
the JSON write.
Fixes deepset-ai#13492
Bensonluo
requested review from
davidsbatista
and removed request for
a team
November 13, 2026 07:49
Contributor
|
@Bensonluo is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
…add key and State tests
Contributor
|
Deployment failed for project haystack-docs with the following error: |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
davidsbatista
approved these changes
Nov 17, 2026
davidsbatista
left a comment
Contributor
There was a problem hiding this comment.
Hi @Bensonluo, thanks for the fix. I did a few changes
- Shorter release note, it's meant to be for users and you should not name internal functions.
- Less duplicated code in _serialize_with_field_fallback: it now only picks which fields to keep, and leaves building the output to _serialize_value_with_schema, so the dict format is defined in one place. The output is the same as before.
- Two new tests + return type hints on the test components
This branch was successfully deployed
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.
Related Issues
Proposed Changes:
_serialize_value_with_schemawrote dicts through theproperties/serialized_datamappings, whose keysjson.dumpstringifies. Resuming a pipeline from a snapshot file therefore turned int keys into strings ({1: "a"}came back as{"1": "a"}) and merged keys that stringify alike ({1: "a", "1": "b"}came back as{"1": "b"}), while the in-memory snapshot in theBreakpointExceptionkept the original keys.Dicts with any non-string key are now serialized as an explicit list of key/value entries, each key with its own schema, and
_deserialize_value_with_schemarebuilds the dict from those entries (with a length check like the existingprefixItemsone). Specifically, inhaystack/utils/base_serialization.py:_serialize_value_with_schemaemits theentriesencoding when a dict has any non-string key, and keeps the historicalpropertiesenvelope for dicts with only string keys._serialize_with_field_fallback's field-by-field path uses the same encoding, and a dict key that cannot be serialized now degrades like a failing value (field omitted with a warning) instead of breaking the JSON write.Statedata, so keys are preserved there too.The
entriesencoding follows the approach proposed in #13497 by @rupak-eng (closed because the CLA was not signed, not for design reasons) — credit for the design belongs there.How did you test it?
TestNonStringKeysintest/utils/test_base_serialization.py: JSON round-trips for int/float/bool/None/mixed/nested/tuple keys and the{1: "a", "1": "b"}collision; the unchanged string-keyed envelope (including a field literally namedentries); the entries length-mismatchDeserializationError; and the field-fallback path with an unserializable value.test/core/pipeline/test_breakpoint.py: the issue's repro — run with a breakpoint onsink, save the snapshot file, load it back and resume; the result keeps{1: "a", 2: "b"}.mainand pass with this change.pytest test/utils/test_base_serialization.py test/core/pipeline/test_breakpoint.py test/components/agents/test_state_class.py→ 152 passed;pytest test/core/pipeline/ test/utils/→ 1204 passed with 11 pre-existing failures reproduced identically on pristinemain(missing optional dependencies in my environment);ruff check,ruff format --check,mypyon the changed module andpre-commithooks all pass.Notes for the reviewer
_serialize_with_field_fallbackdegraded path still drops a field it cannot serialize, as before.Checklist
fix:.From GPT6 and reviewed by person