RishavTiwari25 opened a new pull request, #997:
URL: https://github.com/apache/burr/pull/997
Tuples and sets in state did not survive persistence: they came back as
strings.
```python
persister = SQLLitePersister(db_path=":memory:", table_name="t");
persister.initialize()
state = State({"pair": (1, "a"), "tags": {"x"}, "nested": [(1, 2)]})
persister.save("pk", "app", 0, "a", state, "completed")
persister.load("pk", "app")["state"].get_all()
# {'pair': "(1, 'a')", 'tags': "{'x'}", 'nested': ['(1, 2)']}
```
`serde.serialize` registers handlers for `str`/`int`/`float`/`bool`, `dict`
and `list`. `tuple`, `set` and `frozenset` fell through to the default
implementation, which returns `str(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`: `serialize` handlers for `tuple`, `set` and
`frozenset` that 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 (through
`json.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 a `SQLLitePersister` save/load test.
## How I tested this
- The new tests fail on `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 on `main` too on my machine (graphviz binary not installed;
`test_pickle` compares pickle protocol bytes, which differ on Python 3.14);
`test_langchain.py` was skipped for a missing dependency.
- black (line length 100), isort and flake8 are clean on the changed files.
## Notes
- Values already persisted as strings stay strings; only new saves use the
envelope.
- The tracking UI will show a tuple/set state field as the envelope dict
instead of the `str()` text, the same way it shows other serde-registered types.
- A namedtuple is restored as a plain tuple (before, it was a string).
## Checklist
- [x] PR has an informative and human-readable title (this will be pulled
into the release notes)
- [x] Changes are limited to a single goal (no scope creep)
- [x] Code passed the pre-commit check & code is left cleaner/nicer than
when first encountered.
- [x] Any _change_ in functionality is tested
- [x] New functions are documented (with a description, list of inputs, and
expected output)
- [x] Placeholder code is flagged / future TODOs are captured in comments
- [ ] Project documentation has been updated if adding/changing
functionality.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]