<#4841 [BUG] Asyncio tasks (Python) are returning ...
# flytekit
c
#4841 [BUG] Asyncio tasks (Python) are returning wrong types in eager workflows Issue created by 0100010001001100 ### Describe the bug In eager workflows, if the future/awaitable of a Flyte-task that returns a tuple is wrapped in an asyncio task (Python), then the result of that task will be a named tuple when executed locally and a dictionary when executed remotely (sandbox). See the following example:
Copy code
import asyncio
from flytekit import task
from flytekit.experimental import eager
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config


@task
def square_dual(x: int) -> tuple[int, int]:
    print(f"Computing square of {x}")
    return x**2, x * 2


@eager(
    remote=FlyteRemote(
        config=Config.for_sandbox(),
        default_project="flytesnacks",
        default_domain="development",
    )
)
async def eager_workflow_with_asyncio_tasks(x: int) -> tuple[int, int]:

    pending = {asyncio.create_task(square_dual(x=x))}
    done, pending = await asyncio.wait(pending)
    assert not pending
    task = done.pop()
    result = task.result()
    print(f"{result=}")
    if isinstance(result, dict) and {*result.keys()} == {"o0", "o1"}:
        print("result has wrong type")
        result = result["o0"], result["o1"]
    return result
When executed locally, this will output:
Copy code
Running Execution on local.
Computing square of 3
result=DefaultNamedTupleOutput(o0=9, o1=6)
DefaultNamedTupleOutput(o0=9, o1=6)
When executed remotely (sandbox), this will output:
Copy code
{"asctime": "2024-02-05 15:39:12,944", "name": "flytekit", "levelname": "WARNING", "message": "Plugin 'flytekit-deck-standard' is not installed. To display time line, install the plugin in the image."}
Getting <s3://my-s3-bucket/metadata/propeller/flytesnacks-development-asfspxr4nrt2jj6n2w4t/hpsearchworkflowstesttaskeagerworkflowwithasynciotasks/data/inputs.pb> to /tmp/flyte-sh_gj73f/sandbox/local_flytekit/inputs.pb
result={'o0': 9, 'o1': 6}
result has wrong type
If the output of a Flyte-task is an integer or float, the result (task) is the same, locally and remotely. ### Expected behavior Tasks should return the same types/instances in eager workflows, independent of whether they are executed locally or remotely. ### Additional context to reproduce No response ### Screenshots No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte
a