Skip to content

Commit

Permalink
Filter out remote entity when generating pb (#1545)
Browse files Browse the repository at this point in the history
* Filter out remote entity when generating pb

Signed-off-by: Hongxin Liang <[email protected]>

* Unit test it

Signed-off-by: Hongxin Liang <[email protected]>

* Fix linting

Signed-off-by: Hongxin Liang <[email protected]>

---------

Signed-off-by: Hongxin Liang <[email protected]>
  • Loading branch information
honnix authored Mar 9, 2023
1 parent 7c3c255 commit aee20ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion flytekit/tools/serialize_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from flytekit.models.admin.workflow import WorkflowSpec
from flytekit.models.core import identifier as _identifier
from flytekit.models.task import TaskSpec
from flytekit.remote.remote_callable import RemoteEntity
from flytekit.tools.translator import FlyteControlPlaneEntity, Options, get_serializable


Expand All @@ -40,7 +41,7 @@ def _should_register_with_admin(entity) -> bool:
"""
return isinstance(
entity, (task_models.TaskSpec, _launch_plan_models.LaunchPlan, admin_workflow_models.WorkflowSpec)
)
) and not isinstance(entity, RemoteEntity)


def _find_duplicate_tasks(tasks: typing.List[task_models.TaskSpec]) -> typing.Set[task_models.TaskSpec]:
Expand Down
20 changes: 19 additions & 1 deletion tests/flytekit/unit/cli/pyflyte/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
import flytekit
import flytekit.configuration
import flytekit.tools.serialize_helpers
from flytekit import TaskMetadata
from flytekit.clis.sdk_in_container import pyflyte
from flytekit.core import context_manager
from flytekit.exceptions.user import FlyteValidationException
from flytekit.models.admin.workflow import WorkflowSpec
from flytekit.models.core.identifier import Identifier, ResourceType
from flytekit.models.launch_plan import LaunchPlan
from flytekit.models.task import TaskSpec
from flytekit.remote import FlyteTask
from flytekit.remote.interface import TypedInterface
from flytekit.remote.remote_callable import RemoteEntity

sample_file_contents = """
from flytekit import task, workflow
Expand Down Expand Up @@ -52,12 +57,25 @@ def test_get_registrable_entities():
),
)
)
context_manager.FlyteEntities.entities = [foo, wf, "str"]
context_manager.FlyteEntities.entities = [
foo,
wf,
"str",
FlyteTask(
id=Identifier(ResourceType.TASK, "p", "d", "n", "v"),
type="t",
metadata=TaskMetadata().to_taskmetadata_model(),
interface=TypedInterface(inputs={}, outputs={}),
custom=None,
),
]
entities = flytekit.tools.serialize_helpers.get_registrable_entities(ctx)
assert entities
assert len(entities) == 3

for e in entities:
if isinstance(e, RemoteEntity):
assert False, "found unexpected remote entity"
if isinstance(e, WorkflowSpec) or isinstance(e, TaskSpec) or isinstance(e, LaunchPlan):
continue
assert False, f"found unknown entity {type(e)}"
Expand Down

0 comments on commit aee20ea

Please sign in to comment.