-
Notifications
You must be signed in to change notification settings - Fork 559
[WIP] Fix set serialization in metadata system #4249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Fix set serialization in metadata system #4249
Conversation
084095b to
fcda9c8
Compare
src/zenml/metadata/metadata_types.py
Outdated
| return typed_value # type: ignore[no-any-return] | ||
|
|
||
|
|
||
| def serialize_metadata_value(value: MetadataType) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good implementation. It does cover top-level sets, but for example fails if it's nested in some other element like a dictionary or list. There is a way to do this natively with json encoders, and there even is a pydantic encoder that we use in our code to solve this in other places.
Documentation Link Check Results❌ Absolute links check failed |
04e40e1 to
ffa80a5
Compare
Sets were documented as a supported MetadataType but failed during serialization because json.dumps() cannot serialize Python sets. This change uses the standard pydantic_encoder to convert sets (and tuples) to lists before JSON serialization, making them compatible with JSON while preserving type information via MetadataTypeEnum. The fix uses pydantic_encoder directly (via json.dumps(value, default=pydantic_encoder)) at all serialization points, following the same pattern used throughout the ZenML codebase. This ensures consistency and proper handling of all supported types including nested sets/tuples, UUIDs, datetimes, etc. Changes: - Update validate_metadata() in metadata_types.py to use pydantic_encoder - Update Client.create_run_metadata() to use pydantic_encoder - Update SQLZenStore.create_run_metadata() to use pydantic_encoder - Add unit tests for set/tuple validation - Document supported metadata types in user guide Fixes #4248
ffa80a5 to
6b41e90
Compare
Just running this to run tests
Sets were documented as a supported MetadataType but failed during serialization because json.dumps() cannot serialize Python sets. This change adds a helper function to convert sets (and tuples) to lists before JSON serialization, making them compatible with JSON while preserving type information via MetadataTypeEnum.
Fixes #4248
Pre-requisites
Please ensure you have done the following:
developand the open PR is targetingdevelop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.Types of changes