-
Notifications
You must be signed in to change notification settings - Fork 305
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
Return StructuredDataset which is a field in a dataclass #3071
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Signed-off-by: Nelson Chen <asd3431090@gmail.com>
Code Review Agent Run #63793cActionable Suggestions - 2
Review Details
|
Changelist by BitoThis pull request implements the following key changes.
|
if isinstance(python_val._literal_sd, StructuredDataset): | ||
sdt = StructuredDatasetType(format=python_val._literal_sd.file_format) | ||
metad = literals.StructuredDatasetMetadata(structured_dataset_type=sdt) | ||
sd_literal = literals.StructuredDataset(uri=python_val._literal_sd.uri, metadata=metad) | ||
return Literal(scalar=Scalar(structured_dataset=sd_literal)) |
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.
Accessing private member '_literal_sd'. Consider using a public interface or property to access this data.
Code suggestion
Check the AI-generated fix before applying
- if literal_type.structured_dataset_type is not None and self._literal_sd is not None:
- return self._literal_sd
- if literal_type.structured_dataset_type is not None and self._literal_sd is None:
+ if literal_type.structured_dataset_type is not None and self.literal_sd is not None:
+ return self.literal_sd
+ if literal_type.structured_dataset_type is not None and self.literal_sd is None:
Code Review Run #63793c
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
if isinstance(python_val._literal_sd, StructuredDataset): | ||
sdt = StructuredDatasetType(format=python_val._literal_sd.file_format) | ||
metad = literals.StructuredDatasetMetadata(structured_dataset_type=sdt) | ||
sd_literal = literals.StructuredDataset(uri=python_val._literal_sd.uri, metadata=metad) | ||
return Literal(scalar=Scalar(structured_dataset=sd_literal)) |
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.
The code block for handling StructuredDataset
passed through dataclass could be simplified by extracting the literal creation logic into a helper method. This would improve code readability and maintainability.
Code suggestion
Check the AI-generated fix before applying
if isinstance(python_val._literal_sd, StructuredDataset): | |
sdt = StructuredDatasetType(format=python_val._literal_sd.file_format) | |
metad = literals.StructuredDatasetMetadata(structured_dataset_type=sdt) | |
sd_literal = literals.StructuredDataset(uri=python_val._literal_sd.uri, metadata=metad) | |
return Literal(scalar=Scalar(structured_dataset=sd_literal)) | |
if isinstance(python_val._literal_sd, StructuredDataset): | |
return self._create_structured_dataset_literal(python_val._literal_sd.uri, python_val._literal_sd.file_format) | |
def _create_structured_dataset_literal(self, uri: str, file_format: str) -> Literal: | |
sdt = StructuredDatasetType(format=file_format) | |
metad = literals.StructuredDatasetMetadata(structured_dataset_type=sdt) | |
sd_literal = literals.StructuredDataset(uri=uri, metadata=metad) | |
return Literal(scalar=Scalar(structured_dataset=sd_literal)) |
Code Review Run #63793c
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
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.
it looks correct, can you provide
- screenshot
- add an example to integration test to test it properlly?
test_remote.py
Tracking issue
Related to #6117
Why are the changes needed?
If we wrap the StructuredDataset in a dataclass, it will fail during the to_flyte_idl conversion.
What changes were proposed in this pull request?
Before returning
Literals
, we check the type ofpython_val._literal_sd
. If it is a Python nativeStructuredDataset
, we transform it into aLiterals.StructuredDataset
.How was this patch tested?
As described in #6117, an error occurs when the
extract
task is executed.Setup process
Screenshots
Check all the applicable boxes
Summary by Bito
Fixed a bug in StructuredDataset handling within dataclasses during to_flyte_idl conversion. The PR adds proper transformation of python_val._literal_sd instances into Literals.StructuredDataset, enabling tasks to successfully return StructuredDataset objects as dataclass fields.Unit tests added: False
Estimated effort to review (1-5, lower is better): 1