fix(base): preserve typed serialization results for dataclasses
serialize(value, get_type=True) promises a (serialized_value, type) pair, but the fallback for dataclass instances returns only the fields dictionary. Unpacking fails for zero, one, or more than two fields; with exactly two fields it silently unpacks the dictionary's keys instead of returning the serialized value and type.
Return the fields dictionary together with dict when type information is requested. The default serialization result stays the same, and explicitly registered serializers retain their precedence and declared output type.
Validation:
- Eight regressions cover ordinary/slotted dataclasses with zero through three fields, plus a registered-serializer control. Before the fix, eight fail and the control passes.
- Related serializer tests: 96 passed, 5 skipped on Windows / Python 3.14.
- Changed-file pre-commit checks passed: Ruff format/lint, codespell, stub generation, Pyright, and ty. Unrelated hooks were correctly skipped.
- Added a
reflex-basebugfix news fragment. No generated stubs, dependencies, or unrelated files are included.
The fresh worktree needed its standard generated stubs before the type examples could pass; this was local setup, with no product-source workaround. Database/browser integration tests were not run for this serializer change. AI assistance: OpenAI Codex; submitted through DevChiniwala.
All Submissions
- Checked the contribution guidelines and reviewed the patch.
- Checked for competing open PRs for this return-shape bug.
Type of change
- Bug fix.
Changes To Core Features
- Explained the changed behavior and why it matters.
- Added regression tests and ran related tests locally.