flyte icon indicating copy to clipboard operation
flyte copied to clipboard

[BUG] flytectl get launchplan formats dictionary values incorrectly

Open convexquad opened this issue 4 years ago • 3 comments

Describe the bug

When running flytectl get launchplan --execFile launch_spec.yaml for a workflow that takes a typing.Dict argument that declares a default value, the launch_spec.yaml file formats the default value incorrectly. The default dictionary value retains part of the Golang Protobuf unmarshalling. A fix needs to be made to format the dictionary value as a correct YAML dictionary.

Please note that I cannot solve the problem by just editing the launch_spec.yaml file (as we are writing automated tools that launch workflows with flytectl).

Expected behavior

The following is some of my Python test code on flytekit=1.0.1, flyteadmin=1.1.21, flyteconsole=1.1.0 and flytepropeller=1.1.12:

from typing import Any, Dict, List, Tuple
import os

from flytekit.models.core.execution import WorkflowExecutionPhase
from flytekit.remote.remote import FlyteRemote
from flytekit.types.file import FlyteFile
import flytekit


DEFAULT_PCP_TRIGGER = "kPRT_LIDAR"
EEF_DETECTOR = "eef_detector"
LIDAR_DETECTOR = "lidar_detector"
RADAR_DETECTOR = "radar_detector"
PCP_TRIGGER = "pcp_trigger"
PERCEPTION_DETECTOR = "perception_detector"
VISION_DETECTOR = "vision_detector"


def compose_perception_offline_runner_config() -> Dict[str, Any]:
    return {
        EEF_DETECTOR: {},
        LIDAR_DETECTOR: {
            "num_frames": 3,
            "score_threshold": 0.5,
        },
        PCP_TRIGGER: DEFAULT_PCP_TRIGGER,
        PERCEPTION_DETECTOR: {
            "debug_level": 0,
        },
        RADAR_DETECTOR: {},
        VISION_DETECTOR: {
            "disable_fp16": True,
            "use_annotation": False,
        },
    }


DEFAULT_PCP_STACK_OFFLINE_RUNNER_CONFIG = compose_perception_offline_runner_config()


@flytekit.task(
    limits=flytekit.Resources(cpu="1", mem="256Mi"),
    requests=flytekit.Resources(cpu="1", mem="256Mi"),
)
def old_dict_len_task(
    input_dict1: dict,  # Note that the type here is classic dict
    input_dict2: dict,
) -> Tuple[int, int]:
    return len(input_dict1), len(input_dict2)


@flytekit.workflow
def count_old_dict_len_workflow(
    input_dict: Dict = DEFAULT_PCP_STACK_OFFLINE_RUNNER_CONFIG,  # Type is typing.Dict
) -> Tuple[int, int]:
    len_images1, len_images2 = old_dict_len_task(input_dict1=input_dict, input_dict2=DEFAULT_PCP_STACK_OFFLINE_RUNNER_CONFIG)
    return len_images1, len_images2

If you execute the count_old_dict_len_workflow workflow from Flyte Console, everything works as expected. However, if you use flytectl version 0.6.1 to run flytectl get launchplan --execFile launch_spec.yaml with this workflow, the input_dict argument will be formatted in the launch_spec.yaml file as follows:

alex.bain$ cat launch_spec.yaml 

iamRoleARN: ""
inputs:
    input_dict:
        fields:
            eef_detector:
                kind:
                    structvalue:
                        fields: {}
            lidar_detector:
                kind:
                    structvalue:
                        fields:
                            num_frames:
                                kind:
                                    numbervalue: 3
                            score_threshold:
                                kind:
                                    numbervalue: 0.5
            pcp_trigger:
                kind:
                    stringvalue: kPRT_LIDAR
            perception_detector:
                kind:
                    structvalue:
                        fields:
                            debug_level:
                                kind:
                                    numbervalue: 0
            radar_detector:
                kind:
                    structvalue:
                        fields: {}
            vision_detector:
                kind:
                    structvalue:
                        fields:
                            disable_fp16:
                                kind:
                                    boolvalue: true
                            use_annotation:
                                kind:
                                    boolvalue: false
kubeServiceAcct: ""
targetDomain: ""
targetProject: ""
version: d62f29af7c9da67a6711ac7375d761c7e7be1f78
workflow: app.workflows.fabrik.avsoftware_test_workflow.count_old_dict_len_workflow

As you can see, the input_dict parameter in the serialized YAML file retains elements of Golang Protobuf string formatting (such as kind and structvalue). This is not the correct YAML representation of the dictionary.

The actual dictionary should represent the Python value {"perception_detector":{"debug_level":0},"radar_detector":{},"vision_detector":{"disable_fp16":true,"use_annotation":false},"eef_detector":{},"lidar_detector":{"num_frames":3,"score_threshold":0.5},"pcp_trigger":"kPRT_LIDAR"} as a YAML map.

Are you sure this issue hasn't been raised already?

  • [X] Yes

Have you read the Code of Conduct?

  • [X] Yes

convexquad avatar Jul 07 '22 20:07 convexquad

We are hitting the same issue.

honnix avatar Oct 18 '23 06:10 honnix

I think the problem exists in this function https://github.com/flyteorg/flytectl/blob/043a611097d35b2ad201facd3035a87edd94b1e1/cmd/get/execution_util.go#L153-L158

honnix avatar Oct 18 '23 06:10 honnix

Trying a fix in https://github.com/flyteorg/flytectl/pull/434

honnix avatar Oct 18 '23 07:10 honnix