Skip to content

Improve dataclass serialization#118

Closed
andystaples wants to merge 1 commit intomainfrom
andystaples/fix-dataclass-serialization
Closed

Improve dataclass serialization#118
andystaples wants to merge 1 commit intomainfrom
andystaples/fix-dataclass-serialization

Conversation

@andystaples
Copy link
Contributor

Fixes two bugs with dataclass auto-serialization:
Bug 1 — Nested dataclasses lose the AUTO_SERIALIZED marker:
In shared.py, dataclasses.asdict(obj) was used, which recursively converts all nested dataclass fields into plain dicts. Only the outermost dict received the AUTO_SERIALIZED marker, so inner dataclass objects deserialized as plain dict instead of SimpleNamespace.

Fix: Replaced dataclasses.asdict(obj) with a shallow field extraction. This leaves nested dataclass values as-is, so the encoder calls default() on each one individually, giving each its own AUTO_SERIALIZED marker.

Bug 2 — SimpleNamespace mutation:
vars(obj) returns the object's actual __dict__, not a copy. Adding d[AUTO_SERIALIZED] = True permanently mutated the original SimpleNamespace by injecting an __durabletask_autoobject__ attribute.

Fix: Changed vars(obj) to dict(vars(obj)) to work on a copy.

@andystaples andystaples closed this Mar 2, 2026
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