cuddly-jelly-27016
04/02/2025, 5:03 PMdataclasses json dependency from flytekit V2
Pull request opened by Future-Outlier on <!date^1724650295^{date_short}|2024-08-26T05:31:35Z>
I am going to collaborate with @curved-petabyte-84246, an engineer from Nimble Way to finish this.
## Tracking issue
flyteorg/flyte#4418
## Why are the changes needed?
Reduce container's size.
## What changes were proposed in this pull request?
The philosophy of removing dataclasses-json from flytekit but keep ensuring backward compatibility is to try import dataclasses_json except ImportError for all cases.
When we can't use api from dataclasses-json, we can use mashumaro.
1. inheritance
example: https://github.com/flyteorg/flytekit/pull/2709/files#diff-542ea91d83fb95892fd56588f09967f76665eed2f6cb40afd1fddde776800875R164-R171
(1) get a new class called BaseClass
(2) change every dataclasses with "DataClassJsonMixin" parent class to BaseClass
Before
class ImageConfig(DataClassJsonMixin):
After
try:
from dataclasses_json import DataClassJsonMixin
DataClassBaseClass = DataClassJsonMixin
except ImportError:
DataClassBaseClass = object
class ImageConfig(BaseClass):
1. command line input (click_types)
example: fcb49c8#diff-cc3172a3cdf60bb2ffb23b81cb5b92d6c4a89063d691e86932b312e1df09f292R317-R328
2. from_json and to_json functions
example: fcb49c8#diff-c56afc489e5060224889036253b85ae7c7f1df9f0f7b1130916d9c614293cbb9R963-R968
the from_json and to_json functions are from DataClassJsonMixin
we can should use decoder.decode(json_str) when
if has_attr(from_json):
return cls.from_json(json_str)
else:
decoder = JSONDecoder(SerializationSettings)
return decoder.decode(json_str)
if has_attr(to_json):
json_str = self.to_json()
else:
encoder = JSONEncoder(SerializationSettings)
json_str = encoder.encode(self)
1. get_literal_type
example: https://github.com/flyteorg/flytekit/pull/2709/files#diff-68624e201f644896b015de1a5716eabef9b8b5a106caba1d9f21c51c0708684bR442-R443
from marshmallow_jsonschema import JSONSchema
from mashumaro.jsonschema import build_json_schema
1. dataclass_json()
example: https://github.com/flyteorg/flytekit/pull/2709/files#diff-68624e201f644896b015de1a5716eabef9b8b5a106caba1d9f21c51c0708684bR1849-R1853
2. for unit tests, we should use pytest skip if dataclasses_json is not in the dependency
3. add CI to test cases when we remove dataclass-json
4. add warning logs when dataclasses-json is needed
## 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
#2557
## Docs link
flyteorg/flytekitcuddly-jelly-27016
04/02/2025, 5:03 PMdataclasses json dependency from flytekit V2
Pull request closed by Future-Outlier
flyteorg/flytekit