Hello everyone, tell me how it works, I do not und...
# prefect-community
k
Hello everyone, tell me how it works, I do not understand. Is there an example available? here is the link
a
What is exactly your question here? This page already provides some code examples you may try
k
Copy code
@task(task_run_name="{description}", log_stdout=True)
def transform_data(values):
...
ukey = [val for val in values.keys()][0]
description = "blablabla {key} text text".format(key=ukey)
...
with Flow("flow_name", storage=core_storage) as flow:
    ...
    result=transform_data.map(values):
for example
the problem is that Graph does not reflect information flow.visualize()
a
I see what you mean. So we need to distinguish between two things here. There are: 1. task names 2. and task run names. #1 Is used to provide a name to a task and this is what you can see in the flow visualization. To set this name, you can either: a) set it on the task decorator using the
name
argument:
Copy code
@task(name="some_task_name", task_run_name="{val}")
b) set it within your Flow block by using the
task_args
argument:
Copy code
with Flow("example") as flow:
    result = some_task(task_args={"name": "new-task-name"})
What the documentation you sent describes is #2 task run names and this is something you can see in the UI once you register and run the flow with a backend (e.g. using Prefect Cloud)
k
understandably 😅
👍 1
@Anna Geller will it work like that?
Copy code
from prefect import task, Flow

@task
def get_values():
    return ["value", "test", "demo"]

@task(task_run_name="{val}")
def compute(vals):
    val = "new_task_name"
   return vals

with Flow("task_run_names") as flow:
    vals = get_values()
    compute.map(vals)
a
No, the variable must reference a valid task input - in your compute task, you can reference
vals
rather than
val
Copy code
@task(task_run_name="{vals}")
def compute(vals):
k
then can it be used like this? if value vals = list(), dict()? @task(task run name="{vals[1]}") def compute(vals):
or like this: then can it be used like this? if value vals = List, dictionary? @task(task run name="Text {vals[1]}") def compute(vals):
where vals = [{'key1': 'val1'}, {'key2': 'val2'}]
a
Not sure this is a good pattern to follow. Perhaps you can rethink how you design your task so that there is one string-based input (rather than a list or dict) that you can use as an input that you reference for setting task run names? I think it would be more readable and safer
k
Someone told me using the dictionary works, and I think it would because under the hood is
"{x}".format(x = "text")
.
👀 2