Enhance dict/json export to support field aliases and datetime serialization #14
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.
Fix: Add proper serialization support for FieldMetadata aliases in UncheckedBaseModel
Problem
The Python SDK uses custom
FieldMetadataannotations for field aliasing (e.g.,workflow_run→workflowRun), but these aliases were not being respected during serialization. This caused two critical issues:dict(by_alias=True)- Returned snake_case field names instead of camelCase, and datetime objects weren't JSON-serializablemodel_dump_json(by_alias=True)- Serialized datetimes correctly but still returned snake_case field namesThis prevented users from:
User Impact: Customers reported they couldn't use
model_dump_json(by_alias=True)to get properly formatted JSON output (reported by Ryan O. on Nov 10th)Solution
Added custom serialization methods to
UncheckedBaseModelthat bridge the gap between Pydantic's native serialization and our customFieldMetadataalias system:dict()- AppliesFieldMetadataaliases whenby_alias=Truemodel_dump_json()- Serializes with aliases AND handles datetime conversion_apply_field_aliases()- Recursively transforms snake_case → camelCase usingget_field_to_alias_mapping()_json_serializer()- Helper function for datetime/UUID serializationChanges Made
File:
extend_ai/core/unchecked_base_model.pydict()method override (lines 127-144)model_dump()method override (lines 146-156)model_dump_json()method override (lines 158-171)_apply_field_aliases()helper method (lines 173-220)_json_serializer()helper function (lines 419-426)Testing
Verified with real workflow run data:
Breaking Changes
None. This is purely additive - existing behavior is preserved when
by_alias=False(default).Notes
Field(alias=...)get_field_to_alias_mapping()fromserialization.pyFixes: Issue with
model_dump_json(by_alias=True)not respecting FieldMetadata aliasesRelated: Customer feedback from Ryan O. (Nov 10th)