Repository navigation
Python: fix(workflows): preserve scalar subclasses and IntEnum in checkpoint encoding - #8693
Conversation
…encoding Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
|
Thank you for proposing this change. I am closing this PR for now because it has no linked issue, and I could not find an issue covering this specific problem. Our contribution guidelines ask contributors to create or reuse an issue and discuss the approach before nontrivial changes (with an exception for trivial changes). The repository PR template asks for Motivation & Context, Description & Review Guide, a Related Issue linked with a closing keyword such as |
In _checkpoint_encoding.py, _encode was using isinstance(value, _JSON_NATIVE_TYPES) to determine which scalars pass through directly into JSON. Because IntEnum, StrEnum, and custom scalar subclasses inherit from int or str, isinstance evaluates to True for them.
Consequently, workflow states holding an IntEnum had their types stripped and serialized as raw integers, losing the specific enum or subclass type upon deserialization. This was inconsistent with collection handling in the same file, where type(value) is dict and type(value) is list are checked specifically to preserve subclass fidelity.
This PR updates the scalar check to type(value) in _JSON_NATIVE_TYPES so only exact primitive types bypass pickling, ensuring scalar subclasses and IntEnums retain their class identity on decode. I also added unit tests in test_checkpoint_encode.py.