Fix nested Enum deserialization in checkpoint serde #6763
+6,253
−3
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.
Summary
Fixes #6718 - Nested Enum fields now correctly deserialize from checkpoints instead of becoming None.
Problem
When Pydantic models containing nested enum fields (enums defined inside classes like
DatasetArtifact.PhaseEnum) were checkpointed and restored, the enum values would deserialize asNone, breaking Pydantic validation and causing models to fall back to dicts.Root cause: The serializer used
__name__for class names, which for nested classes only returns the simple name (e.g.,"PhaseEnum"). During deserialization, attemptinggetattr(module, "PhaseEnum")failed because the enum isn't at module level - it's nested insideDatasetArtifact.Solution
__qualname__instead of__name__to preserve nesting info (e.g.,"DatasetArtifact.PhaseEnum")functools.reduceto traverse nested classesNonewhen class resolution fails, allowing Pydantic to reconstruct the enum from the valueTest Plan
test_serde_jsonplus_nested_enum()that verifies:Changes
libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py: Updated enum serialization/deserializationlibs/checkpoint/tests/test_jsonplus.py: Added regression test🤖 Generated with Claude Code