Todd de Quincey
11/02/2021, 6:36 AMTodd de Quincey
11/02/2021, 6:36 AMPostgresExecute
Task, I see that there are a number of kwargs that we can set upon instantiation (e.g. db_name
, host
etc). However, the password
is not set until runtime.
Referring to my simple example below, how are we expected to pass in the password?
with Flow("setup") as flow:
task1 = PostgresExecute(
name="task_name",
db_name="abc,
user="peter,
host="my_host",
port=5432,
query="INSERT INTO blah blah"
# Cannot set the password at intantiation of the task, as it isn't an arg in __init__
)
Todd de Quincey
11/02/2021, 6:53 AMtask1.bind(password=password)
What's the reason for this approach to certain arguments vs setting them at task instantiation?Todd de Quincey
11/02/2021, 7:10 AMTasks were created but not added to the flow: {<Task: lists all tasks>,.
This can occur whenclasses, includingTask
, are instantiated inside aParameters
block but not added to the flow either explicitly or as the input to another task.with flow:
Todd de Quincey
11/02/2021, 7:16 AMAnna Geller
from prefect import Flow, Parameter
name_of_the_parameter_task = Parameter("result_basepath", default="~")
with Flow('Parameterized Flow') as flow:
...
flow.add_task(name_of_the_parameter_task)
Kevin Kho
pgtask = PostgresExecute(...)
with Flow("setup") as flow:
pgtask(...)
or
with Flow("setup") as flow:
x = PostgresExecute(init_here)(run_here)
Todd de Quincey
11/02/2021, 3:55 PMTodd de Quincey
11/02/2021, 3:56 PMTodd de Quincey
11/02/2021, 3:56 PMAnna Geller
bind
method is strictly tied to the imperative API (where tasks are defined as classes rather than functions), but subjectively, just passing the arguments as data dependency seems much easier to understand and more natural - see here line 19 https://gist.github.com/anna-geller/fc29ea1e02113d6a6b20cbaa03ac315e#file-postgres_task_example-py-L19Kevin Kho
Todd de Quincey
11/02/2021, 4:25 PM