Skip to content
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

fix: fix JSONParamType to handle serialization of custom objects #2931

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dalaoqi
Copy link

@dalaoqi dalaoqi commented Nov 14, 2024

Tracking issue

Closes flyteorg/flyte#5985

Why are the changes needed?

The issue arises when trying to serialize lists or dictionaries that contain custom objects, as non-serializable custom objects cause a TypeError by default. This prevents successful serialization of data structures with instances of user-defined classes, necessitating a solution to convert these objects into a JSON-compatible format.

What changes were proposed in this pull request?

This pull request fixes JSON serialization issues for lists and dictionaries containing custom objects by adding support to convert non-serializable objects to JSON-compatible dictionaries.

Added default Parameter to json.dumps: Utilized default=lambda o: o.dict in json.dumps calls to convert non-serializable custom objects into a JSON-compatible dictionary format.

How was this patch tested?

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

@dalaoqi dalaoqi force-pushed the 5985-bug-with-customObject-in-dict-and-list branch from a155053 to 36f98ed Compare November 14, 2024 16:46
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 46.75%. Comparing base (3f0ab84) to head (36f98ed).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
flytekit/interaction/click_types.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2931       +/-   ##
===========================================
- Coverage   76.33%   46.75%   -29.59%     
===========================================
  Files         199      199               
  Lines       20840    20789       -51     
  Branches     2681     2684        +3     
===========================================
- Hits        15908     9719     -6189     
- Misses       4214    10594     +6380     
+ Partials      718      476      -242     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Added a fallback check for `lv.scalar.union.value.collection.literals` in case `lv.collection` is None.
- Prevents potential errors when `lv.collection` is not properly initialized.

Signed-off-by: Tsung-Han Ho (dalaoqi) <[email protected]>
- Added validation to check for duplicate input names in the function's input interface.
- Raised a ValueError if duplicate input names are detected to prevent issues during argument assignment.
- Simplified the conversion of args to kwargs by removing the redundant multiple values check.

Signed-off-by: Tsung-Han Ho (dalaoqi) <[email protected]>
@dalaoqi dalaoqi force-pushed the 5985-bug-with-customObject-in-dict-and-list branch from 2ad9c6c to 1ce0704 Compare November 16, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] dataclass in list default input error
1 participant