-
Notifications
You must be signed in to change notification settings - Fork 300
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
Allow annotated FlyteFile as task input argument #1632
Allow annotated FlyteFile as task input argument #1632
Conversation
Using an annotated FlyteFile type as an input to a task was previously impossible due to an exception being raised in `FlyteFilePathTransformer.to_python_value`. This commit applies the fix previously used in `FlyteFilePathTransformer.to_literal` to permit using annotated FlyteFiles as either inputs and outputs of a task. Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]>
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.
LGTM overall, thanks
flytekit/types/file/file.py
Outdated
if get_origin(t) is Annotated: | ||
return get_args(t)[0] |
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.
we do this all the place in the type_engine.py
.
flytekit/flytekit/core/type_engine.py
Lines 737 to 748 in a1636a8
if get_origin(python_type) is Annotated: | |
python_type = get_args(python_type)[0] | |
if python_type in cls._REGISTRY: | |
return cls._REGISTRY[python_type] | |
# Step 2 | |
if hasattr(python_type, "__origin__"): | |
# Handling of annotated generics, eg: | |
# Annotated[typing.List[int], 'foo'] | |
if get_origin(python_type) is Annotated: | |
return cls.get_transformer(get_args(python_type)[0]) |
could you move this function to
type_engine.py
, and import it instead.
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.
Moved the function there and refactored type_engine.py
quite a bit in 093536f. This should also make the handling of annotated types there more uniform (and added a few tests).
Is this what you had in mind?
Codecov Report
@@ Coverage Diff @@
## master #1632 +/- ##
=======================================
Coverage 71.02% 71.02%
=======================================
Files 336 336
Lines 30724 30736 +12
Branches 5567 5566 -1
=======================================
+ Hits 21821 21831 +10
- Misses 8360 8361 +1
- Partials 543 544 +1
|
Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]>
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.
Thanks, LGTM. would you resolve branch conflict?
…ytefile-2 Signed-off-by: Adrian Rumpold <[email protected]> # Conflicts: # flytekit/core/type_engine.py
Sorry, was sick for the past days, just merged upstream |
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.
@AdrianoKF hope you feel better.
Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]>
@AdrianoKF never mind. That's flaky test. |
* fix: Allow annotated FlyteFile as task input argument Using an annotated FlyteFile type as an input to a task was previously impossible due to an exception being raised in `FlyteFilePathTransformer.to_python_value`. This commit applies the fix previously used in `FlyteFilePathTransformer.to_literal` to permit using annotated FlyteFiles as either inputs and outputs of a task. Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> * refactor: Unified handling of annotated types in type engine Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> * fix: Use py3.8-compatible types in type engine tests Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> --------- Signed-off-by: Adrian Rumpold <[email protected]> Signed-off-by: Arthur <[email protected]>
…)" This reverts commit fe9434f.
* fix: Allow annotated FlyteFile as task input argument Using an annotated FlyteFile type as an input to a task was previously impossible due to an exception being raised in `FlyteFilePathTransformer.to_python_value`. This commit applies the fix previously used in `FlyteFilePathTransformer.to_literal` to permit using annotated FlyteFiles as either inputs and outputs of a task. Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> * refactor: Unified handling of annotated types in type engine Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> * fix: Use py3.8-compatible types in type engine tests Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> --------- Signed-off-by: Adrian Rumpold <[email protected]>
* Multi arch imageSpec (#1630) Multi arch imageSpec (#1630) Signed-off-by: Eduardo Apolinario <[email protected]> * Add executor_path and applications_path to spark config (#1634) * Add executor_path and applications_path to spark config Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> --------- Signed-off-by: Kevin Su <[email protected]> * Add support for env vars to pyflyte run (#1617) * Add support for env vars to pyflyte run Signed-off-by: Kevin Su <[email protected]> * bump idl Signed-off-by: Kevin Su <[email protected]> * update doc Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> --------- Signed-off-by: Kevin Su <[email protected]> Signed-off-by: Eduardo Apolinario <[email protected]> * Fetch task executions in dynamic (#1636) * fetch task executions in dynamic Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> --------- Signed-off-by: Kevin Su <[email protected]> * Added metrics command to pyflyte (#1513) Signed-off-by: Daniel Rammer <[email protected]> * Add http_proxy to client & Fix deviceflow (#1611) * Add http_proxy to client & Fix deviceflow RB=3890720 Signed-off-by: byhsu <[email protected]> * nit Signed-off-by: byhsu <[email protected]> * lint! Signed-off-by: byhsu <[email protected]> --------- Signed-off-by: byhsu <[email protected]> Co-authored-by: byhsu <[email protected]> Signed-off-by: Eduardo Apolinario <[email protected]> * Improve variable names (#1642) Signed-off-by: byhsu <[email protected]> Co-authored-by: byhsu <[email protected]> * Address resolution (#1567) Signed-off-by: Yee Hing Tong <[email protected]> * pyflyte run supports pickle (#1646) Signed-off-by: Kevin Su <[email protected]> * Wait for the pod plugin instead of flytekit (#1647) Signed-off-by: eduardo apolinario <[email protected]> Co-authored-by: eduardo apolinario <[email protected]> * Beautify deviceflow prompt (#1625) * Beautify deviceflow prompt Signed-off-by: byhsu <[email protected]> * lint! Signed-off-by: byhsu <[email protected]> * lint Signed-off-by: byhsu <[email protected]> --------- Signed-off-by: byhsu <[email protected]> Co-authored-by: byhsu <[email protected]> * Improve flytekit register (#1643) * Fix pyflyte register Signed-off-by: byhsu <[email protected]> * revert Signed-off-by: byhsu <[email protected]> * lint Signed-off-by: byhsu <[email protected]> --------- Signed-off-by: byhsu <[email protected]> Co-authored-by: byhsu <[email protected]> * Pass verify flag to all authenticators (#1641) Signed-off-by: byhsu <[email protected]> * Allow annotated FlyteFile as task input argument (#1632) * fix: Allow annotated FlyteFile as task input argument Using an annotated FlyteFile type as an input to a task was previously impossible due to an exception being raised in `FlyteFilePathTransformer.to_python_value`. This commit applies the fix previously used in `FlyteFilePathTransformer.to_literal` to permit using annotated FlyteFiles as either inputs and outputs of a task. Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> * refactor: Unified handling of annotated types in type engine Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> * fix: Use py3.8-compatible types in type engine tests Issue: #3424 Signed-off-by: Adrian Rumpold <[email protected]> --------- Signed-off-by: Adrian Rumpold <[email protected]> * Use logger instead of print statement in sqlalchemy plugin (#1651) * use logging info instead of print Signed-off-by: wirthual <[email protected]> * isorted files Signed-off-by: wirthual <[email protected]> * import root logger from flytekit Signed-off-by: wirthual <[email protected]> --------- Signed-off-by: wirthual <[email protected]> * Map over notebook task (#1650) * map over notebook Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * tests Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * add a flag Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * fix tests Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * Fix tests Signed-off-by: Kevin Su <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> --------- Signed-off-by: Kevin Su <[email protected]> * Support single literals in tiny url (#1654) Signed-off-by: Yee Hing Tong <[email protected]> * Add support overriding image (#1652) Signed-off-by: Kevin Su <[email protected]> * Fix ability to pass None to task with Optional kwarg, add test (#1657) Signed-off-by: Fabio Grätz <[email protected]> Co-authored-by: Fabio Grätz <[email protected]> * Regenerate plugins requirements Signed-off-by: eduardo apolinario <[email protected]> * Regenerate plugins requirements and linting Signed-off-by: eduardo apolinario <[email protected]> * Regenerate whylogs requirements Signed-off-by: eduardo apolinario <[email protected]> --------- Signed-off-by: Eduardo Apolinario <[email protected]> Signed-off-by: Kevin Su <[email protected]> Signed-off-by: Daniel Rammer <[email protected]> Signed-off-by: byhsu <[email protected]> Signed-off-by: Yee Hing Tong <[email protected]> Signed-off-by: eduardo apolinario <[email protected]> Signed-off-by: Adrian Rumpold <[email protected]> Signed-off-by: wirthual <[email protected]> Signed-off-by: Fabio Grätz <[email protected]> Co-authored-by: Kevin Su <[email protected]> Co-authored-by: Dan Rammer <[email protected]> Co-authored-by: ByronHsu <[email protected]> Co-authored-by: byhsu <[email protected]> Co-authored-by: Yee Hing Tong <[email protected]> Co-authored-by: eduardo apolinario <[email protected]> Co-authored-by: Adrian Rumpold <[email protected]> Co-authored-by: wirthual <[email protected]> Co-authored-by: Fabio M. Graetz, Ph.D <[email protected]> Co-authored-by: Fabio Grätz <[email protected]>
TL;DR
This PR allows annotated FlyteFiles to be used as input arguments of a task, e.g., when calculating a custom hash using
Annotated[FlyteFile, HashMethod(...)]
.See the discussion on Slack for additional details.
Type
Are all requirements met?
Complete description
Using an annotated FlyteFile type as an input to a task was previously impossible due to an exception being raised in
FlyteFilePathTransformer.to_python_value
.This MR applies the fix previously used in
FlyteFilePathTransformer.to_literal
to permit using annotated FlyteFiles as either inputs or outputs of a task (see MR #1544), by unwrapping the origin type of the annotated type.Tracking Issue
flyteorg/flyte#3424
Follow-up issue
NA