Skip to content

Commit 44af03f

Browse files
authored
add short_description to Task and Workflow model (#3224)
Signed-off-by: Niels Bantilan <[email protected]>
1 parent 4922dbe commit 44af03f

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

flytekit/models/admin/workflow.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ def from_flyte_idl(cls, pb2_object):
7272

7373

7474
class Workflow(_common.FlyteIdlEntity):
75-
def __init__(self, id, closure):
75+
def __init__(self, id, closure, short_description=None):
7676
"""
7777
:param flytekit.models.core.identifier.Identifier id:
7878
:param WorkflowClosure closure:
7979
"""
8080
self._id = id
8181
self._closure = closure
82+
self._short_description = short_description
8283

8384
@property
8485
def id(self):
@@ -94,11 +95,22 @@ def closure(self):
9495
"""
9596
return self._closure
9697

98+
@property
99+
def short_description(self):
100+
"""
101+
:rtype: str
102+
"""
103+
return self._short_description
104+
97105
def to_flyte_idl(self):
98106
"""
99107
:rtype: flyteidl.admin.workflow_pb2.Workflow
100108
"""
101-
return _admin_workflow.Workflow(id=self.id.to_flyte_idl(), closure=self.closure.to_flyte_idl())
109+
return _admin_workflow.Workflow(
110+
id=self.id.to_flyte_idl(),
111+
closure=self.closure.to_flyte_idl(),
112+
short_description=self.short_description,
113+
)
102114

103115
@classmethod
104116
def from_flyte_idl(cls, pb2_object):
@@ -109,6 +121,7 @@ def from_flyte_idl(cls, pb2_object):
109121
return cls(
110122
id=_identifier.Identifier.from_flyte_idl(pb2_object.id),
111123
closure=WorkflowClosure.from_flyte_idl(pb2_object.closure),
124+
short_description=pb2_object.short_description,
112125
)
113126

114127

flytekit/models/task.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,14 @@ def from_flyte_idl(cls, pb2_object):
701701

702702

703703
class Task(_common.FlyteIdlEntity):
704-
def __init__(self, id, closure):
704+
def __init__(self, id, closure, short_description=None):
705705
"""
706706
:param flytekit.models.core.identifier.Identifier id: The (project, domain, name) identifier for this task.
707707
:param TaskClosure closure: The closure for the underlying workload.
708708
"""
709709
self._id = id
710710
self._closure = closure
711+
self._short_description = short_description
711712

712713
@property
713714
def id(self):
@@ -725,13 +726,22 @@ def closure(self):
725726
"""
726727
return self._closure
727728

729+
@property
730+
def short_description(self):
731+
"""
732+
The short description of the task.
733+
:rtype: str
734+
"""
735+
return self._short_description
736+
728737
def to_flyte_idl(self):
729738
"""
730739
:rtype: flyteidl.admin.task_pb2.Task
731740
"""
732741
return _admin_task.Task(
733742
closure=self.closure.to_flyte_idl(),
734743
id=self.id.to_flyte_idl(),
744+
short_description=self.short_description,
735745
)
736746

737747
@classmethod
@@ -743,6 +753,7 @@ def from_flyte_idl(cls, pb2_object):
743753
return cls(
744754
closure=TaskClosure.from_flyte_idl(pb2_object.closure),
745755
id=_identifier.Identifier.from_flyte_idl(pb2_object.id),
756+
short_description=pb2_object.short_description,
746757
)
747758

748759

tests/flytekit/unit/models/test_tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def test_task(task_closure):
299299
obj = task.Task(
300300
identifier.Identifier(identifier.ResourceType.TASK, "project", "domain", "name", "version"),
301301
task_closure,
302+
"my short description",
302303
)
303304
assert obj.id.project == "project"
304305
assert obj.id.domain == "domain"

tests/flytekit/unit/remote/test_remote.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,15 @@ def get_compiled_workflow_closure():
390390
def test_fetch_lazy(remote):
391391
mock_client = remote._client
392392
mock_client.get_task.return_value = Task(
393-
id=Identifier(ResourceType.TASK, "p", "d", "n", "v"), closure=LIST_OF_TASK_CLOSURES[0]
393+
id=Identifier(ResourceType.TASK, "p", "d", "n", "v"),
394+
closure=LIST_OF_TASK_CLOSURES[0],
395+
short_description="task description",
394396
)
395397

396398
mock_client.get_workflow.return_value = Workflow(
397399
id=Identifier(ResourceType.TASK, "p", "d", "n", "v"),
398400
closure=WorkflowClosure(compiled_workflow=get_compiled_workflow_closure()),
401+
short_description="workflow description",
399402
)
400403

401404
lw = remote.fetch_workflow_lazy(name="wn", version="v")
@@ -453,8 +456,9 @@ def test_launch_backfill(remote):
453456
mock_client.get_workflow.return_value = Workflow(
454457
id=Identifier(ResourceType.WORKFLOW, "p", "d", "daily2", "v"),
455458
closure=WorkflowClosure(
456-
compiled_workflow=CompiledWorkflowClosure(primary=ser_wf, sub_workflows=[], tasks=tasks)
459+
compiled_workflow=CompiledWorkflowClosure(primary=ser_wf, sub_workflows=[], tasks=tasks),
457460
),
461+
short_description="workflow description",
458462
)
459463

460464
wf = remote.launch_backfill(
@@ -478,6 +482,7 @@ def test_fetch_workflow_with_branch(mock_promote, mock_workflow, remote):
478482
mock_client.get_workflow.return_value = Workflow(
479483
id=Identifier(ResourceType.TASK, "p", "d", "n", "v"),
480484
closure=WorkflowClosure(compiled_workflow=MagicMock()),
485+
short_description="workflow description",
481486
)
482487

483488
admin_launch_plan = MagicMock()
@@ -496,6 +501,7 @@ def test_fetch_workflow_with_nested_branch(mock_promote, mock_workflow, remote):
496501
mock_client.get_workflow.return_value = Workflow(
497502
id=Identifier(ResourceType.TASK, "p", "d", "n", "v"),
498503
closure=WorkflowClosure(compiled_workflow=MagicMock()),
504+
short_description="workflow description",
499505
)
500506
admin_launch_plan = MagicMock()
501507
admin_launch_plan.spec = {"workflow_id": 123}
@@ -866,7 +872,6 @@ def workflow1():
866872
assert isinstance(registered_workflow, FlyteWorkflow)
867873
assert registered_workflow.id == Identifier(ResourceType.WORKFLOW, "flytesnacks", "development", "tests.flytekit.unit.remote.test_remote.workflow1", "dummy_version")
868874

869-
870875
@mock.patch("flytekit.remote.remote.get_serializable")
871876
@mock.patch("flytekit.remote.remote.FlyteRemote.fetch_launch_plan")
872877
@mock.patch("flytekit.remote.remote.FlyteRemote.raw_register")

0 commit comments

Comments
 (0)