[Python] Support for Event containing Row field can be json serializable#63
Conversation
|
@Kavishankarks Thanks a lot for the contribution, I will take a look later. And I created the correspond issue #64 , which you can take. |
|
Thanks for your contribution, @Kavishankarks. LGTM. |
|
It seems we are always trying the pydantic serialization first, and fallback to json serialization with custom serializer if the first try fail. This approach leads to a few issues.
I think the most elegant approach might be making the pyflink WDYT? @Kavishankarks @wenjin272 |
I think it make sense to avoid the issues. Firstly, I try the monkey patches, but it occurs exception Then, I try to find some methods to inject customer serializer to BaseModel model_dump_json(). Fortunately, there is exactly a fallback parameters when call model_dump_json() So, I modify the Event code like: And it works WDYT? @Kavishankarks @xintongsong |
I think this solution of using monkey patch looks more suitable. |
|
@wenjin272 shall I make the suggested changes? |
@Kavishankarks Of course you can. |
|
Hi, @Kavishankarks, do you have time recently to make revisions based on the comments? |
|
Hi @wenjin272, i have done the changes, please review at your convieniece. |
LGTM. |
Linked issue: #64
This change introduces enhanced JSON serialization support for Row objects within the Event class in the Flink Agents module. Specifically:
Adds a custom row_serializer() function to convert PyFlink Row instances into serializable dictionaries.
Implements model_dump_json() override and _serialize_with_row_support() to gracefully handle Row serialization across all events.
Adds utility methods to detect serialization issues exclusively caused by Row objects, preventing false-positive validation errors.
Includes test coverage for both valid and invalid serialization cases involving Row and non-serializable types.