Repository navigation
fix(serde): round-trip tuples and sets in persisted state - #997
Open
RishavTiwari25 wants to merge 1 commit into
Open
RishavTiwari25 wants to merge 1 commit into
RishavTiwari25 wants to merge 1 commit into
Conversation
serialize() had no handler for tuple, set or frozenset, so they fell through to the default str(value). A state value (1, 'a') was persisted as the string "(1, 'a')" and loaded back as that string, and the same happened to sets and to tuples nested in lists or dicts. They are now serialized element by element in a serde envelope and deserialized back to the same type.
This branch has not been 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.
Tuples and sets in state did not survive persistence: they came back as strings.
serde.serializeregisters handlers forstr/int/float/bool,dictandlist.tuple,setandfrozensetfell through to the default implementation, which returnsstr(value), and nothing turns that string back. So an app that keeps e.g.(role, content)pairs or a set of seen ids in state gets strings after it is restored from a persister.Changes
burr/core/serde.py:serializehandlers fortuple,setandfrozensetthat serialize each element (so nested values still go through serde) inside an envelope ({"__burr_serde__": "builtins.tuple" | "builtins.set" | "builtins.frozenset", "value": [...]}), plus the matching deserializers that rebuild the same type.tests/core/test_serde.py: round-trip tests (throughjson.dumps/json.loads, as persisters store it) for tuples, empty tuples, sets, empty sets, frozensets, and tuples/sets nested in lists, dicts and sets, checking value and type; and aSQLLitePersistersave/load test.How I tested this
main(8 of them) and pass with the change.pytest tests/core tests/tracking tests/visibility tests/test_end_to_end.py tests/integrations/serde: 485 passed. The 6 failures there fail onmaintoo on my machine (graphviz binary not installed;test_picklecompares pickle protocol bytes, which differ on Python 3.14);test_langchain.pywas skipped for a missing dependency.Notes
str()text, the same way it shows other serde-registered types.Checklist