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

Support with_overrides setting metadata for map_task subnode instead of parent node #2982

Merged
merged 5 commits into from
Jan 18, 2025

Conversation

pvditt
Copy link
Contributor

@pvditt pvditt commented Dec 5, 2024

Tracking issue

fixes: https://linear.app/unionai/issue/COR-2498/with-overrides-sets-metadata-for-parent-instead-of-subnode-for-map

Why are the changes needed?

with_overrides doesn't work for map_tasks

What changes were proposed in this pull request?

create a new field in array node map task to explicitl

How was this patch tested?

  • added unit tests
  • tested workflows locally that overrode timeouts, cache, container image, etc

Setup process

from flytekit import task, workflow, map_task, reference_launch_plan, reference_task, ImageSpec, LaunchPlan, Resources, TaskMetadata
from datetime import timedelta


@task(
    cache=True,
    cache_version="v1.0",
    timeout=timedelta(seconds=20),
    container_image="pvditt/flytekit:15",
    interruptible=False,
    retries=12,
)
def basic_cache(num: str) -> str:
    return f"Hi: {num[0]} ugh-1"


@workflow()
def map_metadata_wf() -> list[str]:
    a = ["1", "2", "3", "4", "5"]
    return map_task(basic_cache)(num=a).with_overrides(
        cache_version="v1.1", 
        timeout=timedelta(seconds=10), 
        container_image="pvditt/flytekit:20",
        interruptible=True,
        retries=10,
    )

Screenshots

image

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

Fixed a critical bug in map_tasks where metadata was incorrectly being set on parent nodes instead of subnodes. Implemented dedicated sub_node_metadata field and refactored override logic for proper application of settings (timeout, cache, container image) to mapped subtasks. Simplified metadata access by removing getter method and using direct property access while maintaining backward compatibility.

Unit tests added: False

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

@flyte-bot
Copy link
Contributor

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - The AI Code Review Agent skipped reviewing this change because it is configured to exclude certain pull requests based on the source/target branch or the pull request status. You can change the settings here, or contact the agent instance creator at [email protected].

Signed-off-by: Paul Dittamo <[email protected]>
@pvditt
Copy link
Contributor Author

pvditt commented Jan 9, 2025

noticed a separate issue: flyteorg/flyte#6153 - will get a quick fix for this after this is merged. Also need to follow up with fixing this for ArrayNode (mapping over ref tasks that I need to upstream the BE changes for)

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 9, 2025

Code Review Agent Run #a0a338

Actionable Suggestions - 2
  • flytekit/core/array_node_map_task.py - 1
    • Consider using constructor for name setting · Line 131-132
  • flytekit/tools/translator.py - 1
    • Consider backward compatibility for method rename · Line 627-627
Additional Suggestions - 1
  • flytekit/core/node.py - 1
    • Consider simplifying retry strategy initialization · Line 155-156
Review Details
  • Files reviewed - 4 · Commit Range: 7a54e96..fe58977
    • flytekit/core/array_node_map_task.py
    • flytekit/core/node.py
    • flytekit/tools/translator.py
    • tests/flytekit/unit/core/test_array_node_map_task.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

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 9, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Bug Fix - Fix Map Task Metadata Override Functionality

array_node_map_task.py - Added sub_node_metadata field and refactored metadata handling

node.py - Implemented _override_node_metadata method for proper metadata inheritance

translator.py - Updated metadata reference to use sub_node_metadata

test_array_node_map_task.py - Added comprehensive tests for map task metadata overrides

Comment on lines +131 to +132
self.sub_node_metadata: NodeMetadata = super().construct_node_metadata()
self.sub_node_metadata._name = self.name
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using constructor for name setting

Consider using the constructor parameters to set the name property when creating NodeMetadata instead of modifying the protected _name attribute directly. This would follow better encapsulation practices.

Code suggestion
Check the AI-generated fix before applying
Suggested change
self.sub_node_metadata: NodeMetadata = super().construct_node_metadata()
self.sub_node_metadata._name = self.name
self.sub_node_metadata: NodeMetadata = NodeMetadata(name=self.name, timeout=self.metadata.timeout, retries=self.metadata.retry_strategy, interruptible=self.metadata.interruptible)

Code Review Run #a0a338


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

  • it was incorrectly flagged

@@ -624,7 +624,7 @@ def get_serializable_array_node_map_task(
)
node = workflow_model.Node(
id=entity.name,
metadata=entity.construct_sub_node_metadata(),
metadata=entity.get_sub_node_metadata(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider backward compatibility for method rename

Consider if renaming the method from construct_sub_node_metadata() to get_sub_node_metadata() maintains backward compatibility. This change could potentially break existing code that relies on the old method name.

Code suggestion
Check the AI-generated fix before applying
Suggested change
metadata=entity.get_sub_node_metadata(),
metadata=entity.construct_sub_node_metadata() if hasattr(entity, 'construct_sub_node_metadata') else entity.get_sub_node_metadata(),

Code Review Run #a0a338


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

  • it was incorrectly flagged

thomasjpfan
thomasjpfan previously approved these changes Jan 11, 2025
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Minor nit, otherwise LGTM

Comment on lines 150 to 151
def get_sub_node_metadata(self) -> NodeMetadata:
return self.sub_node_metadata
Copy link
Member

Choose a reason for hiding this comment

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

The pattern in flytekit is to use a property + a private attribute:

@property
def sub_node_metadata(self) -> NodeMetadata:
    return self._sub_node_metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for pointing this out. just updated

Signed-off-by: Paul Dittamo <[email protected]>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 13, 2025

Code Review Agent Run #e417ab

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: fe58977..550ca24
    • flytekit/core/array_node_map_task.py
    • flytekit/tools/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

@pvditt pvditt requested a review from thomasjpfan January 13, 2025 17:00
@thomasjpfan thomasjpfan merged commit abf0d41 into master Jan 18, 2025
105 checks passed
shuyingliang pushed a commit to shuyingliang/flytekit that referenced this pull request Jan 22, 2025
…of parent node (flyteorg#2982)

* test

Signed-off-by: Paul Dittamo <[email protected]>

* add support for with_overrides for map tasks

Signed-off-by: Paul Dittamo <[email protected]>

* expand unit test

Signed-off-by: Paul Dittamo <[email protected]>

* cleanup

Signed-off-by: Paul Dittamo <[email protected]>

---------

Signed-off-by: Paul Dittamo <[email protected]>
eapolinario pushed a commit that referenced this pull request Jan 22, 2025
…of parent node (#2982)

* test

Signed-off-by: Paul Dittamo <[email protected]>

* add support for with_overrides for map tasks

Signed-off-by: Paul Dittamo <[email protected]>

* expand unit test

Signed-off-by: Paul Dittamo <[email protected]>

* cleanup

Signed-off-by: Paul Dittamo <[email protected]>

---------

Signed-off-by: Paul Dittamo <[email protected]>
eapolinario added a commit that referenced this pull request Jan 22, 2025
* Make FlyteUserRuntimeException to return error_code in Container Error (#3059)

* Make FlyteUserRuntimeException to return error_code in the ContainerError

Signed-off-by: Rafael Ribeiro Raposo <[email protected]>

* [Flytekit] Separate remote signal functions (#2933)

* feat: separate remote signal functions

Signed-off-by: mao3267 <[email protected]>

* refactor: make lint

Signed-off-by: mao3267 <[email protected]>

* test: add integration test for separated signal functions

Signed-off-by: mao3267 <[email protected]>

* fix: register workflow to admin

Signed-off-by: mao3267 <[email protected]>

* fix: integration test and approve function

Signed-off-by: mao3267 <[email protected]>

* fix: remove approve node output

Signed-off-by: mao3267 <[email protected]>

* fix: replace single sleep command to retry statement

Signed-off-by: mao3267 <[email protected]>

* fix: update comments

Signed-off-by: mao3267 <[email protected]>

* fix: simplify duplicate retry operations

Signed-off-by: mao3267 <[email protected]>

---------

Signed-off-by: mao3267 <[email protected]>

* Only copy over cat-certificates.crt if it does not exist in base image  (#3067)

* Do not copy over ca-certifcates.crt if the base image has one

Signed-off-by: Thomas J. Fan <[email protected]>

* Only copy over cat-certificates.crt if it does not exist in base image

Signed-off-by: Thomas J. Fan <[email protected]>

---------

Signed-off-by: Thomas J. Fan <[email protected]>

* Support with_overrides setting metadata for map_task subnode instead of parent node (#2982)

* test

Signed-off-by: Paul Dittamo <[email protected]>

* add support for with_overrides for map tasks

Signed-off-by: Paul Dittamo <[email protected]>

* expand unit test

Signed-off-by: Paul Dittamo <[email protected]>

* cleanup

Signed-off-by: Paul Dittamo <[email protected]>

---------

Signed-off-by: Paul Dittamo <[email protected]>

* fix: remove duplication log when execute (#3052)

Signed-off-by: Vincent <[email protected]>

* Fix: Always propagate pytorch task worker process exception timestamp to task exception (#3057)

* Fix: Always propagate pytorch task worker process exception timestamp to task exception

Signed-off-by: Fabio Grätz <[email protected]>

* Fix exist recoverable error test

Signed-off-by: Fabio Grätz <[email protected]>

---------

Signed-off-by: Fabio Grätz <[email protected]>
Co-authored-by: Fabio Grätz <[email protected]>

* Allow user-defined dataclass type transformer (again) (#3075)

* Allow for user-defined dataclass type tranformers

Signed-off-by: Eduardo Apolinario <[email protected]>

* Finish comment and remote user-defined dataclass transformer from registry

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Rafael Ribeiro Raposo <[email protected]>
Signed-off-by: mao3267 <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Paul Dittamo <[email protected]>
Signed-off-by: Vincent <[email protected]>
Signed-off-by: Fabio Grätz <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Rafael Raposo <[email protected]>
Co-authored-by: Vincent Chen <[email protected]>
Co-authored-by: Thomas J. Fan <[email protected]>
Co-authored-by: Paul Dittamo <[email protected]>
Co-authored-by: V <[email protected]>
Co-authored-by: Fabio M. Graetz, Ph.D. <[email protected]>
Co-authored-by: Fabio Grätz <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
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.

3 participants