fix: gcs_object_metadata_client can't handle required_tasks#467
fix: gcs_object_metadata_client can't handle required_tasks#467
Conversation
|
@TlexCypher Hi! Could you review this? |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for serializing required_task_outputs into object metadata in GCSObjectMetadataClient and includes a new test for this functionality.
- Extend
_get_patched_obj_metadatato includerequired_task_outputs - Implement
_get_serialized_stringto handle single, dict, and iterable inputs with type checking - Add a unit test for the new
required_task_outputsparameter
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/test_gcs_obj_metadata_client.py | Imported RequiredTaskOutput and added test_get_patched_obj_metadata_with_required_task_outputs |
| gokart/gcs_obj_metadata_client.py | Removed early return, added support for required_task_outputs, updated _get_serialized_string logic |
Comments suppressed due to low confidence (5)
gokart/gcs_obj_metadata_client.py:117
- The return type annotation
FlattenableItems[str]doesn't reflect that this method may return dicts or lists; consider updating the type hint and/or renaming the method to match its actual outputs.
def _get_serialized_string(required_task_outputs: FlattenableItems[RequiredTaskOutput]) -> FlattenableItems[str]:
gokart/gcs_obj_metadata_client.py:98
- The new
required_task_outputsparameter isn't described in this method's docstring; please update the docstring to explain its purpose and supported types.
def _get_patched_obj_metadata(
test/test_gcs_obj_metadata_client.py:117
- Add tests for passing a single
RequiredTaskOutputinstance and a dict of outputs to cover all branches in_get_serialized_string.
def test_get_patched_obj_metadata_with_required_task_outputs(self):
test/test_gcs_obj_metadata_client.py:117
- Include a test case that verifies a
TypeErroris raised when an unsupported type is passed torequired_task_outputs.
def test_get_patched_obj_metadata_with_required_task_outputs(self):
gokart/gcs_obj_metadata_client.py:122
- Ensure
Iterableis imported (fromcollections.abcortyping) to avoid a potentialNameErrorat runtime.
elif isinstance(required_task_outputs, Iterable):
|
|
||
| @staticmethod | ||
| def _get_serialized_string(required_task_outputs: FlattenableItems[RequiredTaskOutput]) -> FlattenableItems[str]: | ||
| def _iterable_flatten(nested_list: Iterable) -> Iterable[str]: |
There was a problem hiding this comment.
Ah—since str is also an Iterable, calling:
_iterable_flatten([["a"]]) will never terminate.
The following implementation of _iterable_flatten works correctly:
def _iterable_flatten(nested_list: Iterable) -> Iterable[str]:
for item in nested_list:
if isinstance(item, str):
yield item
elif isinstance(item, Iterable):
yield from _iterable_flatten(item)
else:
yield item
However, since recursion is only needed for _get_serialized_string, you removed iterable_flatten entirely, right? @kitagry
There was a problem hiding this comment.
@kitagry Please include that background in the PR comment for future reference.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
a6f101b to
ed10eb8
Compare
Hi-king
left a comment
There was a problem hiding this comment.
Confirmed this logic clearly converts FlattenableItems[RequiredTaskOutput] into FlattenableItems[str]. :)
LGTM.
|
@kitagry |
fix #466
This pull request fix the
_get_patched_obj_metadatamethod ingokart/gcs_obj_metadata_client.py.In original code, we doesn't consider
strtype, so RecursionError was occurred. like #466 .In this PR, I made the code simple and add tests in order to check the behaviors.