``` [4/4] currentAttempt done. Last Error: USER::P...
# ask-the-community
s
Copy code
[4/4] currentAttempt done. Last Error: USER::Pod failed. No message received from kubernetes.
[a29fz6979nbn4dxsr7km-n0-3] terminated with exit code (1). Reason [Error]. Message: 
Traceback (most recent call last):
  File "/opt/venv/bin/pyflyte-execute", line 8, in <module>
    sys.exit(execute_task_cmd())
  File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/flytekit/bin/entrypoint.py", line 470, in execute_task_cmd
    _execute_task(
  File "/opt/venv/lib/python3.8/site-packages/flytekit/exceptions/scopes.py", line 160, in system_entry_point
    return wrapped(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/flytekit/bin/entrypoint.py", line 348, in _execute_task
    _handle_annotated_task(ctx, _task_def, inputs, output_prefix)
  File "/opt/venv/lib/python3.8/site-packages/flytekit/bin/entrypoint.py", line 291, in _handle_annotated_task
    _dispatch_execute(ctx, task_def, inputs, output_prefix)
  File "/opt/venv/lib/python3.8/site-packages/flytekit/bin/entrypoint.py", line 80, in _dispatch_execute
    logger.debug(f"Starting _dispatch_execute for {task_def.name}")
AttributeError: 'function' object has no attribute 'name'
e
@seunggs, can you share the definition of the task and also how you're invoking it in a workflow?
s
In
/project-root/flyte/workflows
, I have
test_wf.py
with the following code
Copy code
from flytekit import Resources, task, workflow
from src.test_tasks import add_one
from src.test_tasks import double

add_one_task=task(requests=Resources(cpu="1"),limits=Resources(cpu="1"),retries=3)(add_one)
double_task=task(requests=Resources(cpu="1"),limits=Resources(cpu="1"),retries=3)(double)

@workflow
def test_wf_1(x:int):
	add_one_task_output_=add_one_task(x=x)
	double_task_output_=double_task(x=add_one_task_output_)
	return {"result":{"double_task":double_task_output_}}
And in
/project-root/src/test_tasks.py
, I have the following code:
Copy code
def add_one(x: int) -> int:
    return x + 1

def double(x: int) -> int:
    return x * 2
In
/project-root
I’m running
pyflyte package …
and then
flytectl register…
The workflow seems to deploy fine but when I run execute from the console, I see the above error
The first task (add_one) fails
e
@seunggs, if you move the definition of the tasks to inside the workflow it should work:, e.g.:
Copy code
...

@workflow
def test_wf_1(x:int):
    add_one_task=task(requests=Resources(cpu="1"),limits=Resources(cpu="1"),retries=3)(add_one)    double_task=task(requests=Resources(cpu="1"),limits=Resources(cpu="1"),retries=3)(double)
    add_one_task_output_=add_one_task(x=x)
	double_task_output_=double_task(x=add_one_task_output_)
	return {"result":{"double_task":double_task_output_}}
s
Hmm interesting - why would this make a difference?
Based on the documentation, @task decorator is always used outside of @workflow?
e
yeah, this is an interesting case.
@task
makes an assumption that it will be invoked inside a workflow
I guess we could be able to make this work, but it doesn't work now (and it's also completely broken in the local execution case)
s
Wait I’m confused - your hello world example has @task outside of @workflow
Are you saying that’s incorrect?
e
wait, indentation is wrong, let me paste the full example:
Copy code
from flytekit import task, workflow, Resources

def add_one(x: int) -> int:
    return x + 1


@workflow
def test_wf_1(x:int):
    add_one_task=task(add_one, requests=Resources(cpu="1"),limits=Resources(cpu="1"),retries=3)
    # This also works
    # add_one_task=task(requests=Resources(cpu="1"),limits=Resources(cpu="1"),retries=3)(add_one)

    add_one_task_output_=add_one_task(x=x)
    return {"result":{"add_one_task_output":add_one_task_output_}}
s
@Eduardo Apolinario (eapolinario) I think you missed my messages above: your hello world example has @task outside of @workflow - are you saying that this documentation is incorrect?
e
sorry, the docs are correct, I was referring to the way you were composing the tasks outside of a
@workflow
(this is not supported today).
s
Because I’m using the decorator as a function?
e
yes
s
Ah I see
Interesting - I thought they were completely equivalent
e
yeah, in most cases they are, but we setup the environment used by the
@task
decorator in a
@workflow
most cases == most decorators not
@task
though
s
Ah interesting ok
Good that I asked - I would’ve never figured this out on my own lol
Thank you!
e
s
OK I’ll take a look at this
e
the gist is that the code inside
@workflow
smells like python but it's indeed a DSL defined in flytekit
s
Right I remember that - I thought @task themselves are just python decorators though and would have no impact on this, but I was wrong
Thank you - I’ll read through this more carefully
e
cool. And if you feel like this can be explained more simply, please reach out, we're always looking out for opportunities to improve docs.
Contributions are more than welcome! ❤️
s
Got it - the way I’m using it is a bit unorthodox for sure but will report back if it’d be useful
Thanks!!
e
awesome. I'm curious to see what you came up with!
160 Views