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

feat: support positional args for ref entity #3104

Merged
merged 10 commits into from
Feb 21, 2025

Conversation

machichima
Copy link
Contributor

@machichima machichima commented Feb 2, 2025

Tracking issue

Similar to issue: flyteorg/flyte#5320, but for reference entities

Why are the changes needed?

Support positional args for reference task, workflow, and launch plan.

Originally, following code will fail with error like: FlyteAssertion: USER:AssertionError: error=Cannot call reference entity with args - detected 2 positional args (Promise(node:.x.[]), Promise(node:.y.[]))

@reference_task(
    project="flytesnacks",
    domain="development",
    name="ref_workflow.base_list_adder",
    version="FmnTvGOpEnjm2XrxeYF7EA",
)
def base_list_adder(x: list[int], y: list[int]) -> list[int]:
    ...

@workflow
def wf(x: list[int], y: list[int]) -> list[int]:
    return base_list_adder(x, y)

What changes were proposed in this pull request?

Write values in positional arguments (args) into kwargs

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

Summary by Bito

This PR implements comprehensive Flytekit enhancements including: positional argument support for reference entities, improved task caching with configurable policies, shared memory support in containers, better Ray task configuration and pod template handling, enhanced remote execution monitoring, and updated agent implementations with LiteralMap for output handling. These changes focus on improving system reliability, maintainability, and authentication mechanisms with expanded test coverage.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 5

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 2, 2025

Code Review Agent Run #942e72

Actionable Suggestions - 1
  • flytekit/core/reference_entity.py - 1
    • Consider impact of keyword to positional change · Line 189-189
Review Details
  • Files reviewed - 2 · Commit Range: 88f3f80..6956e28
    • flytekit/core/promise.py
    • flytekit/core/reference_entity.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.24%. Comparing base (66d4aed) to head (8544ace).

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3104       +/-   ##
===========================================
+ Coverage   76.85%   95.24%   +18.38%     
===========================================
  Files         206       85      -121     
  Lines       21851     3803    -18048     
  Branches     2837        0     -2837     
===========================================
- Hits        16794     3622    -13172     
+ Misses       4269      181     -4088     
+ Partials      788        0      -788     

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

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 2, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Enhanced Reference Entity Argument Handling

reference_entity.py - Improved argument handling to support positional args with better validation

test_references.py - Added comprehensive tests for positional argument support in reference tasks, workflows, and launch plans

@@ -187,7 +186,7 @@ def construct_node_metadata(self) -> _workflow_model.NodeMetadata:
return _workflow_model.NodeMetadata(name=extract_obj_name(self.name))

def compile(self, ctx: FlyteContext, *args, **kwargs):
return create_and_link_node(ctx, entity=self, **kwargs)
return create_and_link_node(ctx, self, *args, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider impact of keyword to positional change

Consider if the change from entity=self to positional argument self could impact any callers expecting keyword arguments. The function signature in create_and_link_node expects entity as a keyword parameter.

Code suggestion
Check the AI-generated fix before applying
Suggested change
return create_and_link_node(ctx, self, *args, **kwargs)
return create_and_link_node(ctx, entity=self, *args, **kwargs)

Code Review Run #942e72


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@@ -200,10 +199,6 @@ def __call__(self, *args, **kwargs):
# nothing. Subsequent tasks will have to know how to unwrap these. If by chance a non-Flyte task uses a
# task output as an input, things probably will fail pretty obviously.
# Since this is a reference entity, it still needs to be mocked otherwise an exception will be raised.
if len(args) > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we convert args to kwargs here instead? Then, we don't need to change the signature of create_and_link_node

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be great to have a small test for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I will modify it and add some tests

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 9, 2025

Code Review Agent Run #204b34

Actionable Suggestions - 2
  • flytekit/core/reference_entity.py - 2
    • Fix undefined variable in error message · Line 208-208
    • Fix undefined variable in duplicate arg message · Line 214-214
Additional Suggestions - 10
  • flytekit/models/domain.py - 1
    • Consider adding input validation for parameters · Line 14-16
  • flytekit/image_spec/default_builder.py - 2
    • Consider adding pip secret mount validation · Line 486-488
    • Consider extracting secret mount string logic · Line 224-229
  • tests/flytekit/unit/core/test_node_creation.py - 1
    • Consider extracting PodTemplate config for clarity · Line 481-499
  • tests/flytekit/unit/clients/auth/test_keyring_store.py - 1
  • tests/flytekit/unit/core/test_array_node_map_task.py - 1
    • Consider testing additional override parameters · Line 352-361
  • flytekit/remote/remote.py - 2
  • flytekit/image_spec/image_spec.py - 2
    • Consider adding validation for secret mounts · Line 51-53
    • Consider extracting pip_secret_mounts validation logic · Line 134-141
Review Details
  • Files reviewed - 40 · Commit Range: 6956e28..c3ab907
    • dev-requirements.txt
    • flytekit/bin/entrypoint.py
    • flytekit/clients/auth_helper.py
    • flytekit/clients/friendly.py
    • flytekit/clients/grpc_utils/auth_interceptor.py
    • flytekit/clients/raw.py
    • flytekit/core/base_task.py
    • flytekit/core/context_manager.py
    • flytekit/core/node.py
    • flytekit/core/promise.py
    • flytekit/core/reference_entity.py
    • flytekit/core/type_engine.py
    • flytekit/deck/deck.py
    • flytekit/image_spec/default_builder.py
    • flytekit/image_spec/image_spec.py
    • flytekit/loggers.py
    • flytekit/models/core/workflow.py
    • flytekit/models/domain.py
    • flytekit/models/security.py
    • flytekit/models/task.py
    • flytekit/remote/remote.py
    • flytekit/tools/fast_registration.py
    • flytekit/tools/translator.py
    • flytekit/types/directory/types.py
    • pydoclint-errors-baseline.txt
    • pyproject.toml
    • tests/flytekit/unit/clients/auth/test_keyring_store.py
    • tests/flytekit/unit/clients/test_auth_helper.py
    • tests/flytekit/unit/clients/test_friendly.py
    • tests/flytekit/unit/clients/test_raw.py
    • tests/flytekit/unit/core/image_spec/test_default_builder.py
    • tests/flytekit/unit/core/image_spec/test_image_spec.py
    • tests/flytekit/unit/core/test_array_node_map_task.py
    • tests/flytekit/unit/core/test_map_task.py
    • tests/flytekit/unit/core/test_node_creation.py
    • tests/flytekit/unit/core/test_references.py
    • tests/flytekit/unit/core/test_unions.py
    • tests/flytekit/unit/deck/test_deck.py
    • tests/flytekit/unit/models/core/test_security.py
    • tests/flytekit/unit/test_translator.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

# Check if we have more arguments than expected
if len(args) > len(interface.inputs):
raise AssertionError(
f"Received more arguments than expected in function '{entity.name}'. Expected {len(interface.inputs)} but got {len(args)}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix undefined variable in error message

The error message in the AssertionError references an undefined entity.name. Consider using self.name instead since this is within the ReferenceEntity class.

Code suggestion
Check the AI-generated fix before applying
Suggested change
f"Received more arguments than expected in function '{entity.name}'. Expected {len(interface.inputs)} but got {len(args)}"
f"Received more arguments than expected in function '{self.name}'. Expected {len(interface.inputs)} but got {len(args)}"

Code Review Run #204b34


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

# Convert args to kwargs
for arg, input_name in zip(args, interface.inputs.keys()):
if input_name in kwargs:
raise AssertionError(f"Got multiple values for argument '{input_name}' in function '{entity.name}'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix undefined variable in duplicate arg message

Similar to the previous issue, the error message uses entity.name which is undefined. Consider using self.name for consistency.

Code suggestion
Check the AI-generated fix before applying
Suggested change
raise AssertionError(f"Got multiple values for argument '{input_name}' in function '{entity.name}'")
raise AssertionError(f"Got multiple values for argument '{input_name}' in function '{self.name}'")

Code Review Run #204b34


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Signed-off-by: machichima <[email protected]>
Future-Outlier
Future-Outlier previously approved these changes Feb 14, 2025
Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 14, 2025

Code Review Agent Run #90a123

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: c3ab907..77260a7
    • flytekit/core/reference_entity.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

pingsutw
pingsutw previously approved these changes Feb 14, 2025
Copy link
Member

@pingsutw pingsutw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@pingsutw pingsutw enabled auto-merge (squash) February 14, 2025 22:09
@machichima machichima dismissed stale reviews from pingsutw and Future-Outlier via 8544ace February 18, 2025 13:27
@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 18, 2025

Code Review Agent Run #e70869

Actionable Suggestions - 0
Additional Suggestions - 10
  • flytekit/core/python_auto_container.py - 1
    • Consider adding shared memory validation · Line 55-55
  • flytekit/configuration/plugin.py - 1
    • Consider default implementation for cache policies · Line 58-59
  • flytekit/core/task.py - 1
    • Consider adding Optional to cache type hint · Line 139-139
  • flytekit/core/worker_queue.py - 3
  • pyproject.toml - 1
    • Consider adding version upper bound · Line 23-23
  • tests/flytekit/unit/core/test_node_creation.py - 1
  • tests/flytekit/unit/models/test_execution.py - 1
    • Consider testing False case for interruptible · Line 169-169
  • flytekit/models/execution.py - 1
    • Consider adding validation for interruptible parameter · Line 219-219
Review Details
  • Files reviewed - 52 · Commit Range: 77260a7..8544ace
    • flytekit/__init__.py
    • flytekit/clis/sdk_in_container/init.py
    • flytekit/clis/sdk_in_container/run.py
    • flytekit/configuration/plugin.py
    • flytekit/core/cache.py
    • flytekit/core/constants.py
    • flytekit/core/node.py
    • flytekit/core/promise.py
    • flytekit/core/python_auto_container.py
    • flytekit/core/python_function_task.py
    • flytekit/core/resources.py
    • flytekit/core/task.py
    • flytekit/core/type_engine.py
    • flytekit/core/type_match_checking.py
    • flytekit/core/worker_queue.py
    • flytekit/core/workflow.py
    • flytekit/interaction/click_types.py
    • flytekit/interaction/string_literals.py
    • flytekit/loggers.py
    • flytekit/models/core/workflow.py
    • flytekit/models/execution.py
    • flytekit/models/task.py
    • flytekit/remote/data.py
    • flytekit/remote/remote.py
    • flytekit/utils/rate_limiter.py
    • plugins/flytekit-aws-sagemaker/tests/test_boto3_agent.py
    • plugins/flytekit-onnx-pytorch/dev-requirements.txt
    • plugins/flytekit-openai/tests/openai_batch/test_agent.py
    • plugins/flytekit-pandera/flytekitplugins/pandera/pandas_transformer.py
    • plugins/flytekit-pandera/setup.py
    • pyproject.toml
    • tests/flytekit/integration/remote/test_remote.py
    • tests/flytekit/integration/remote/workflows/basic/dataclass_wf.py
    • tests/flytekit/unit/bin/test_python_entrypoint.py
    • tests/flytekit/unit/cli/pyflyte/test_run.py
    • tests/flytekit/unit/cli/pyflyte/test_run_lps.py
    • tests/flytekit/unit/core/test_annotated_bindings.py
    • tests/flytekit/unit/core/test_array_node_map_task.py
    • tests/flytekit/unit/core/test_cache.py
    • tests/flytekit/unit/core/test_generice_idl_type_engine.py
    • tests/flytekit/unit/core/test_node_creation.py
    • tests/flytekit/unit/core/test_resources.py
    • tests/flytekit/unit/core/test_type_engine.py
    • tests/flytekit/unit/core/test_type_match_checking.py
    • tests/flytekit/unit/core/test_worker_queue.py
    • tests/flytekit/unit/interaction/test_click_types.py
    • tests/flytekit/unit/interaction/test_string_literals.py
    • tests/flytekit/unit/models/core/test_workflow.py
    • tests/flytekit/unit/models/test_execution.py
    • tests/flytekit/unit/models/test_tasks.py
    • tests/flytekit/unit/types/structured_dataset/test_structured_dataset.py
    • tests/flytekit/unit/utils/test_rate_limiter.py
  • Files skipped - 1
    • .gitignore - Reason: Filter setting
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 20, 2025

Code Review Agent Run #8bdf2a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 12 · Commit Range: 8544ace..95aab21
    • flytekit/clis/sdk_in_container/serve.py
    • flytekit/core/type_engine.py
    • flytekit/remote/remote.py
    • plugins/flytekit-aws-sagemaker/flytekitplugins/awssagemaker_inference/boto3_agent.py
    • plugins/flytekit-aws-sagemaker/tests/test_boto3_agent.py
    • plugins/flytekit-greatexpectations/tests/test_schema.py
    • plugins/flytekit-openai/flytekitplugins/openai/batch/agent.py
    • plugins/flytekit-openai/tests/openai_batch/test_agent.py
    • plugins/flytekit-ray/flytekitplugins/ray/task.py
    • plugins/flytekit-ray/tests/test_ray.py
    • tests/flytekit/integration/remote/test_remote.py
    • tests/flytekit/integration/remote/workflows/basic/deep_child_workflow.py
  • Files skipped - 3
    • .github/workflows/build_image.yml - Reason: Filter setting
    • .github/workflows/pythonbuild.yml - Reason: Filter setting
    • .github/workflows/pythonpublish.yml - Reason: Filter setting
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@pingsutw pingsutw merged commit 74cdcfb into flyteorg:master Feb 21, 2025
110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants