https://prefect.io logo
Title
m

Matt Delacour

09/26/2022, 3:38 PM
Do Parameters work for Task that are classes and not functions? https://docs-v1.prefect.io/core/concepts/parameters.html I am trying to pass a Parameter to a ShellTask but it does not look like it works. Any example of that?
1️⃣ 1
1
shell_task = ShellTask(
    log_stdout=True,
    log_stderr=True,
    stream_output=True,
)

with Flow(
    "model_on_demand",
) as flow:
    select = Parameter("select", required=True)
    shell_task(command=f"echo '{select}'")
This returns the class and not the value of the Parameter ...
b

Bianca Hoch

09/26/2022, 4:21 PM
Hi Matt, this user asked a similar question. They were able to have the custom task accept the parameter value via the .run() method. Let us know if the example helps.
m

Matt Delacour

09/26/2022, 4:44 PM
So the solution is to
run()
the Parameter (which is a Task) But it's not recognized as an "input" so I cannot trigger the flow with different values of the Parameter in the Web UI So I don't believe that this is a good solution. Maybe I don't understand it
b

Bianca Hoch

09/26/2022, 9:11 PM
After reviewing this with the team, the following example should work for you:
shell_task = ShellTask(
    log_stdout=True,
    log_stderr=True,
    stream_output=True,
)

@task
def generate_command(select):
   return f"echo '{select}'"

with Flow(
    "model_on_demand",
) as flow:
    select = Parameter("select", required=True)
    shell_task(command=generate_command(select))
The string for the command needs to be set within a task. It can't be set within the
with Flow(…)
block because nothing has values at that point.
m

Matt Delacour

09/27/2022, 4:54 PM
will try that. Thank you
So it sounds like it works for
ShellTask
but not for
DbtShellTask
which is a child of it ...
class DbtShellTask(ShellTask):
    pass
🤔
Untitled.py
Actually even in the ShellTask it does not work
@task
def generate_command(select: str) -> str:
    return f"--select {select}"


with Flow(
    "model_on_demand",
) as dbt_flow:
    # Models to run on demand
    select = Parameter("select", required=True)
    shell_task(command=f"echo 'HELLO {generate_command(select=select)}'")
Ok I got it 👍
🚀 1
1