<#3598 [BUG] TypeError: 'NoneType' object is not i...
# flyte-github
a
#3598 [BUG] TypeError: 'NoneType' object is not iterable when running a documentation example Issue created by raisadz Describe the bug Hi, I just tried to reproduce an example from the documentation (https://docs.flyte.org/projects/cookbook/en/latest/auto/core/containerization/raw_container.html). I have the following files:
example_container.py
Copy code
import logging
import os

from flytekit import ContainerTask, kwtypes, task, workflow

logger = logging.getLogger(__file__)


calculate_ellipse_area_python = ContainerTask(
    name="ellipse-area-metadata-python",
    input_data_dir="/var/inputs",
    output_data_dir="/var/outputs",
    inputs=kwtypes(a=float, b=float),
    outputs=kwtypes(area=float, metadata=str),
    image="<http://ghcr.io/flyteorg/rawcontainers-python:v2|ghcr.io/flyteorg/rawcontainers-python:v2>",
    command=[
        "python",
        "calculate-ellipse-area.py",
        "{{.inputs.a}}",
        "{{.inputs.b}}",
        "/var/outputs"
    ],
)

@task
def report_all_calculated_areas(
    area_python: float,
    metadata_python: str
):
    <http://logger.info|logger.info>(f"python: area={area_python}, metadata={metadata_python}")


@workflow
def wf(a: float, b: float):
    area_python, metadata_python = calculate_ellipse_area_python(a=a, b=b)

    # Report on all results in a single task to simplify comparison
    report_all_calculated_areas(
        area_python=area_python,
        metadata_python=metadata_python
    )

if __name__ == "__main__":
    wf(a=3.0, b = 4.0)
and
calculate-ellipse-area.py
Copy code
import math
import sys
import os


def write_output(output_dir, output_file, v):
    if os.path.isdir(f"{output_dir}") == False:
        os.makedirs(f"{output_dir}")
    with open(f"{output_dir}/{output_file}", "w") as f:
        f.write(str(v))


def calculate_area(a, b):
    return math.pi * a * b


def main(a, b, output_dir):
    if os.path.exists('var/inputs') == False:
        os.makedirs('var/inputs')
    a = float(a)
    b = float(b)

    area = calculate_area(a, b)

    write_output(output_dir, "area", area)
    write_output(output_dir, "metadata", "[from python rawcontainer]")


if __name__ == "__main__":
    a = sys.argv[1]
    b = sys.argv[2]
    output_dir = sys.argv[3]

    main(a, b, output_dir)
Then I tried to run
pyflyte
but got the following error:
Copy code
$ pyflyte run example_container.py wf --a 2.0 --b 3.0
{"asctime": "2023-04-15 12:54:36,959", "name": "flytekit", "levelname": "WARNING", "message": "FlyteSchema is deprecated, use Structured Dataset instead."}
{'a': 2.0, 'b': 3.0}

docker run --rm -v /tmp/inputs:/var/inputs -v /tmp/outputs:/var/outputs <http://ghcr.io/flyteorg/rawcontainers-python:v2|ghcr.io/flyteorg/rawcontainers-python:v2> ['python', 'calculate-ellipse-area.py', '{{.inputs.a}}', '{{.inputs.b}}', '/var/outputs'] None
Failed with Unknown Exception <class 'TypeError'> Reason: 'NoneType' object is not iterable
'NoneType' object is not iterable
Expected behavior Not to error Additional context to reproduce I also tried running
example_container.py
directly with Python, and got:
Copy code
$ python example_container.py
{"asctime": "2023-04-15 12:54:48,793", "name": "flytekit", "levelname": "WARNING", "message": "FlyteSchema is deprecated, use Structured Dataset instead."}
{'a': 3.0, 'b': 4.0}

docker run --rm -v /tmp/inputs:/var/inputs -v /tmp/outputs:/var/outputs <http://ghcr.io/flyteorg/rawcontainers-python:v2|ghcr.io/flyteorg/rawcontainers-python:v2> ['python', 'calculate-ellipse-area.py', '{{.inputs.a}}', '{{.inputs.b}}', '/var/outputs'] None
Traceback (most recent call last):
  File "/path/to/flyte/flyte-projects/example/example_container.py", line 44, in <module>
    wf(a=3.0, b = 4.0)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/workflow.py", line 263, in __call__
    return flyte_entity_call_handler(self, *args, **input_kwargs)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/promise.py", line 1087, in flyte_entity_call_handler
    result = cast(LocallyExecutable, entity).local_execute(child_ctx, **kwargs)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/workflow.py", line 282, in local_execute
    function_outputs = self.execute(**kwargs)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/workflow.py", line 722, in execute
    return exception_scopes.user_entry_point(self._workflow_function)(**kwargs)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/exceptions/scopes.py", line 198, in user_entry_point
    return wrapped(*args, **kwargs)
  File "/path/to/flyte/flyte-projects/example/example_container.py", line 35, in wf
    area_python, metadata_python = calculate_ellipse_area_python(a=a, b=b)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/base_task.py", line 299, in __call__
    return flyte_entity_call_handler(self, *args, **kwargs)  # type: ignore
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/promise.py", line 1079, in flyte_entity_call_handler
    return cast(LocallyExecutable, entity).local_execute(ctx, **kwargs)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/base_task.py", line 280, in local_execute
    outputs_literal_map = self.sandbox_execute(ctx, input_literal_map)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/base_task.py", line 346, in sandbox_execute
    return self.dispatch_execute(ctx, input_literal_map)
  File "/path/to/env/lib/python3.10/site-packages/flytekit/core/base_task.py", line 556, in dispatch_execute
    expected_output_names[i]: native_outputs[i] for i, _ in enumerate(native_outputs)
TypeError: 'NoneType' object is not iterable
Screenshots No response Are you sure this issue hasn't been raised already? ☑︎ Yes Have you read the Code of Conduct? ☑︎ Yes flyteorg/flyte