Skip to content

Commit 919c948

Browse files
authored
add metadata_defaults to workflow constructor (#93)
* add metadata_defaults to workflow constructor * uncomment out test
1 parent 9f3b48f commit 919c948

3 files changed

Lines changed: 86 additions & 86 deletions

File tree

flytekit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from __future__ import absolute_import
22
import flytekit.plugins
33

4-
__version__ = '0.6.0b2'
4+
__version__ = '0.6.0b3'

flytekit/common/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class SdkWorkflow(
8484
)
8585
):
8686

87-
def __init__(self, inputs, outputs, nodes, id=None, metadata=None, interface=None, output_bindings=None):
87+
def __init__(self, inputs, outputs, nodes, id=None, metadata=None, metadata_defaults=None, interface=None, output_bindings=None):
8888
"""
8989
:param list[flytekit.common.promise.Input] inputs:
9090
:param list[Output] outputs:

tests/flytekit/unit/common_tests/test_workflow_promote.py

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -114,57 +114,57 @@ class OneTaskWFForPromote(object):
114114
# Commenting these tests out for now until we can find a way to ensure
115115
# these tests pass on all flyteidl changes.
116116

117-
# @_patch("flytekit.common.tasks.task.SdkTask.fetch")
118-
# def test_basic_workflow_promote(mock_task_fetch):
119-
# # This section defines a sample workflow from a user
120-
# @_sdk_tasks.inputs(a=_Types.Integer)
121-
# @_sdk_tasks.outputs(b=_Types.Integer, c=_Types.Integer)
122-
# @_sdk_tasks.python_task()
123-
# def demo_task_for_promote(wf_params, a, b, c):
124-
# b.set(a + 1)
125-
# c.set(a + 2)
126-
127-
# @_sdk_workflow.workflow_class()
128-
# class TestPromoteExampleWf(object):
129-
# wf_input = _sdk_workflow.Input(_Types.Integer, required=True)
130-
# my_task_node = demo_task_for_promote(a=wf_input)
131-
# wf_output_b = _sdk_workflow.Output(my_task_node.outputs.b, sdk_type=_Types.Integer)
132-
# wf_output_c = _sdk_workflow.Output(my_task_node.outputs.c, sdk_type=_Types.Integer)
133-
134-
# # This section uses the TaskTemplate stored in Admin to promote back to an Sdk Workflow
135-
# int_type = _types.LiteralType(_types.SimpleType.INTEGER)
136-
# task_interface = _interface.TypedInterface(
137-
# # inputs
138-
# {'a': _interface.Variable(int_type, "description1")},
139-
# # outputs
140-
# {
141-
# 'b': _interface.Variable(int_type, "description2"),
142-
# 'c': _interface.Variable(int_type, "description3")
143-
# }
144-
# )
145-
# # Since the promotion of a workflow requires retrieving the task from Admin, we mock the SdkTask to return
146-
# task_template = _task_model.TaskTemplate(
147-
# _identifier.Identifier(_identifier.ResourceType.TASK, "project", "domain",
148-
# "tests.flytekit.unit.common_tests.test_workflow_promote.demo_task_for_promote",
149-
# "version"),
150-
# "python_container",
151-
# get_sample_task_metadata(),
152-
# task_interface,
153-
# custom={},
154-
# container=get_sample_container()
155-
# )
156-
# sdk_promoted_task = _task.SdkTask.promote_from_model(task_template)
157-
# mock_task_fetch.return_value = sdk_promoted_task
158-
# workflow_template = get_workflow_template()
159-
# promoted_wf = _workflow_common.SdkWorkflow.promote_from_model(workflow_template)
160-
161-
# assert promoted_wf.interface.inputs["wf_input"] == TestPromoteExampleWf.interface.inputs["wf_input"]
162-
# assert promoted_wf.interface.outputs["wf_output_b"] == TestPromoteExampleWf.interface.outputs["wf_output_b"]
163-
# assert promoted_wf.interface.outputs["wf_output_c"] == TestPromoteExampleWf.interface.outputs["wf_output_c"]
164-
165-
# assert len(promoted_wf.nodes) == 1
166-
# assert len(TestPromoteExampleWf.nodes) == 1
167-
# assert promoted_wf.nodes[0].inputs[0] == TestPromoteExampleWf.nodes[0].inputs[0]
117+
@_patch("flytekit.common.tasks.task.SdkTask.fetch")
118+
def test_basic_workflow_promote(mock_task_fetch):
119+
# This section defines a sample workflow from a user
120+
@_sdk_tasks.inputs(a=_Types.Integer)
121+
@_sdk_tasks.outputs(b=_Types.Integer, c=_Types.Integer)
122+
@_sdk_tasks.python_task()
123+
def demo_task_for_promote(wf_params, a, b, c):
124+
b.set(a + 1)
125+
c.set(a + 2)
126+
127+
@_sdk_workflow.workflow_class()
128+
class TestPromoteExampleWf(object):
129+
wf_input = _sdk_workflow.Input(_Types.Integer, required=True)
130+
my_task_node = demo_task_for_promote(a=wf_input)
131+
wf_output_b = _sdk_workflow.Output(my_task_node.outputs.b, sdk_type=_Types.Integer)
132+
wf_output_c = _sdk_workflow.Output(my_task_node.outputs.c, sdk_type=_Types.Integer)
133+
134+
# This section uses the TaskTemplate stored in Admin to promote back to an Sdk Workflow
135+
int_type = _types.LiteralType(_types.SimpleType.INTEGER)
136+
task_interface = _interface.TypedInterface(
137+
# inputs
138+
{'a': _interface.Variable(int_type, "description1")},
139+
# outputs
140+
{
141+
'b': _interface.Variable(int_type, "description2"),
142+
'c': _interface.Variable(int_type, "description3")
143+
}
144+
)
145+
# Since the promotion of a workflow requires retrieving the task from Admin, we mock the SdkTask to return
146+
task_template = _task_model.TaskTemplate(
147+
_identifier.Identifier(_identifier.ResourceType.TASK, "project", "domain",
148+
"tests.flytekit.unit.common_tests.test_workflow_promote.demo_task_for_promote",
149+
"version"),
150+
"python_container",
151+
get_sample_task_metadata(),
152+
task_interface,
153+
custom={},
154+
container=get_sample_container()
155+
)
156+
sdk_promoted_task = _task.SdkTask.promote_from_model(task_template)
157+
mock_task_fetch.return_value = sdk_promoted_task
158+
workflow_template = get_workflow_template()
159+
promoted_wf = _workflow_common.SdkWorkflow.promote_from_model(workflow_template)
160+
161+
assert promoted_wf.interface.inputs["wf_input"] == TestPromoteExampleWf.interface.inputs["wf_input"]
162+
assert promoted_wf.interface.outputs["wf_output_b"] == TestPromoteExampleWf.interface.outputs["wf_output_b"]
163+
assert promoted_wf.interface.outputs["wf_output_c"] == TestPromoteExampleWf.interface.outputs["wf_output_c"]
164+
165+
assert len(promoted_wf.nodes) == 1
166+
assert len(TestPromoteExampleWf.nodes) == 1
167+
assert promoted_wf.nodes[0].inputs[0] == TestPromoteExampleWf.nodes[0].inputs[0]
168168

169169

170170
def get_compiled_workflow_closure():
@@ -181,36 +181,36 @@ def get_compiled_workflow_closure():
181181
return _compiler_model.CompiledWorkflowClosure.from_flyte_idl(cwc_pb)
182182

183183

184-
# def test_subworkflow_promote():
185-
# cwc = get_compiled_workflow_closure()
186-
# primary = cwc.primary
187-
# sub_workflow_map = {sw.template.id: sw.template for sw in cwc.sub_workflows}
188-
# task_map = {t.template.id: t.template for t in cwc.tasks}
189-
# promoted_wf = _workflow_common.SdkWorkflow.promote_from_model(primary.template, sub_workflow_map, task_map)
190-
191-
# # This file that the promoted_wf reads contains the compiled workflow closure protobuf retrieved from Admin
192-
# # after registering a workflow that basically looks like the one below.
193-
194-
# @inputs(num=Types.Integer)
195-
# @outputs(out=Types.Integer)
196-
# @python_task
197-
# def inner_task(wf_params, num, out):
198-
# wf_params.logging.info("Running inner task... setting output to input")
199-
# out.set(num)
200-
201-
# @workflow_class()
202-
# class IdentityWorkflow(object):
203-
# a = Input(Types.Integer, default=5, help="Input for inner workflow")
204-
# odd_nums_task = inner_task(num=a)
205-
# task_output = Output(odd_nums_task.outputs.out, sdk_type=Types.Integer)
206-
207-
# @workflow_class()
208-
# class StaticSubWorkflowCaller(object):
209-
# outer_a = Input(Types.Integer, default=5, help="Input for inner workflow")
210-
# identity_wf_execution = IdentityWorkflow(a=outer_a)
211-
# wf_output = Output(identity_wf_execution.outputs.task_output, sdk_type=Types.Integer)
212-
213-
# assert StaticSubWorkflowCaller.interface == promoted_wf.interface
214-
# assert StaticSubWorkflowCaller.nodes[0].id == promoted_wf.nodes[0].id
215-
# assert StaticSubWorkflowCaller.nodes[0].inputs == promoted_wf.nodes[0].inputs
216-
# assert StaticSubWorkflowCaller.outputs == promoted_wf.outputs
184+
def test_subworkflow_promote():
185+
cwc = get_compiled_workflow_closure()
186+
primary = cwc.primary
187+
sub_workflow_map = {sw.template.id: sw.template for sw in cwc.sub_workflows}
188+
task_map = {t.template.id: t.template for t in cwc.tasks}
189+
promoted_wf = _workflow_common.SdkWorkflow.promote_from_model(primary.template, sub_workflow_map, task_map)
190+
191+
# This file that the promoted_wf reads contains the compiled workflow closure protobuf retrieved from Admin
192+
# after registering a workflow that basically looks like the one below.
193+
194+
@inputs(num=Types.Integer)
195+
@outputs(out=Types.Integer)
196+
@python_task
197+
def inner_task(wf_params, num, out):
198+
wf_params.logging.info("Running inner task... setting output to input")
199+
out.set(num)
200+
201+
@workflow_class()
202+
class IdentityWorkflow(object):
203+
a = Input(Types.Integer, default=5, help="Input for inner workflow")
204+
odd_nums_task = inner_task(num=a)
205+
task_output = Output(odd_nums_task.outputs.out, sdk_type=Types.Integer)
206+
207+
@workflow_class()
208+
class StaticSubWorkflowCaller(object):
209+
outer_a = Input(Types.Integer, default=5, help="Input for inner workflow")
210+
identity_wf_execution = IdentityWorkflow(a=outer_a)
211+
wf_output = Output(identity_wf_execution.outputs.task_output, sdk_type=Types.Integer)
212+
213+
assert StaticSubWorkflowCaller.interface == promoted_wf.interface
214+
assert StaticSubWorkflowCaller.nodes[0].id == promoted_wf.nodes[0].id
215+
assert StaticSubWorkflowCaller.nodes[0].inputs == promoted_wf.nodes[0].inputs
216+
assert StaticSubWorkflowCaller.outputs == promoted_wf.outputs

0 commit comments

Comments
 (0)