https://prefect.io logo
Title
a

Andres

02/10/2023, 3:20 PM
Hello, currently migrating from prefect v1 to v2 and I'm trying to find the way of passing this argument to a generic task as I was doing it on v1. Is it possible on v2?
task_args={"name": "current-task-run-name"}
c

Christopher Boyd

02/10/2023, 4:16 PM
This should be an option I think unless I misunderstand your question - https://docs.prefect.io/api-ref/prefect/tasks/ Task_run_name is a field
a

Andres

02/13/2023, 11:54 AM
Yeah, I've seen this, but I try adding the task_run_name parameter when calling the task and I get:
got an unexpected keyword argument 'task_run_name'.
c

Christopher Boyd

02/13/2023, 1:39 PM
How are you setting it? It’s in the object, so that’s surprising. https://github.com/PrefectHQ/prefect/blob/main/src/prefect/tasks.py#L176
a

Andres

02/13/2023, 3:52 PM
yeah, I know, I've been through the code too 😕 I just add
task_run_name="task_name"
as a parameter to the task
c

Christopher Boyd

02/13/2023, 3:54 PM
Have you tried using it like:
@task(task_run_name="task_name")
or is that what you mean?
a

Andres

02/13/2023, 3:58 PM
no, what I'm trying to do is the following. I define a task:
@task(name="generic-task-name")
def task_a(name: str):
    print(f"Hello {name}")
and then call it withing the flow like this:
@flow(name="Amazing-flow")
def my_flow():
    task_a("Andres",task_run_name="task-to-say-hello-to-andres")
this was possible on lower versions of prefect afaik
@Christopher Boyd is the above possible?
c

Christopher Boyd

02/14/2023, 1:43 PM
Without explicitly testing it myself, I don’t know . Looking at the error you’re receiving, it’s because
task_a(name: str)
does not have
task_run_name
defined, so you’re passing an argument that only exists in the wrapper