Skip to content

fix(serialization): preserve slotted dataclass fields - #640

Draft
Kayvan-Zahiri wants to merge 1 commit into
rungalileo:mainfrom
Kayvan-Zahiri:codex/serialize-slotted-dataclasses
Draft

Kayvan-Zahiri wants to merge 1 commit into
rungalileo:mainfrom
Kayvan-Zahiri:codex/serialize-slotted-dataclasses

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

A @dataclass(slots=True) instance has no __dict__. The generic dataclass branch in EventSerializer raises AttributeError and silently replaces the complete value with a non-serializable placeholder, losing its fields in trace data. The existing LangGraph-specific branch avoids this for Command, but other slotted dataclasses still fail.

Read declared fields with dataclasses.fields and getattr, including inherited slots. Preserve any existing instance dictionary entries to retain support for dynamic attributes on ordinary dataclasses, and continue recursively serializing field values through the existing serializer.

Add 16 cases through serialize_to_str and json.dumps(..., cls=EventSerializer): inherited dataclasses, slots/ordinary storage, frozen/mutable values, nested/direct payloads, and UUID field values. Tests follow the repository's Given/When/Then convention.

Validation on Python 3.13:

  • Before: 8 new failures and 8 passing ordinary-dataclass controls. All16 pass after the fix.
  • Entire serialization module:85 passed,8 optional LangGraph/proto-plus skips,2 pre-existing pytest collection warnings. Run with --noconftest -o addopts='' to isolate the serialization module from unrelated integration fixtures.
  • Relevant dependencies use repository lock versions:OpenAI2.32.0,LangChainCore1.2.7,Pydantic2.12.5,Mypy1.17.1. An initial run with newer OpenAI failed2 existing snapshots because the new client exposes an extra admin_api_key attribute; those pass with the locked version.
  • Changed runtime file passes Ruff0.12.12 and mypy; both changed files pass Ruff formatting and whitespace checks.
  • Existing test file has7 pre-existing PLC0415 findings, verified against its untouched HEAD content; no new lint findings.
  • Source distribution and wheel build successfully.

No generated resources, live API calls, or customer data. Full framework/integration suite was not run.

@baz-reviewer

baz-reviewer Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review this PR on Baz

Baz Summary

Update EventSerializer to read declared dataclass fields with fields and getattr, preserving inherited and slotted values while retaining dynamic instance attributes and recursive serialization. Expand serialization coverage across slots, mutability, inheritance, nesting, UUIDs, and both supported JSON entry points.

Latest Contributors(0)
UserCommitDate


Merger  Activate to get a short verdict whether this PR is good to go or not

Skills  Activate Skill Maintainer to keep your skills up to date

Planner  This PR would have been improved with Baz Planner - Try it now

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.

1 participant