https://prefect.io logo
Title
a

Alex Post

12/04/2019, 6:18 PM
Hi - I'm having an issue with setting a parameter according to the documentation found here: https://docs.prefect.io/core/concepts/parameters.html My flow looks like this:
with Flow('Kafka Data Quality Test') as flow:
    full_run = Parameter('full_run', default=False)

flow.run(parameters=dict(full_run=True))
and I keep getting this error:
Traceback (most recent call last):
  File "src/app.py", line 243, in <module>
    flow.run(parameters=dict(full_run=True))
  File "/Users/apost/ccde/ccde-kafka-data-quality/venv/lib/python3.7/site-packages/prefect/core/flow.py", line 991, in run
    fmt_params
ValueError: Flow.run received the following unexpected parameters: full_run
Has anyone seen this before?
j

josh

12/04/2019, 6:22 PM
Hey @Alex Post instantiating the
Parameter
does not actually add it to the flow and you will need to either call
flow.add_task
for that parameter or use it in another task!
e.g.
@task
def p(param):
    print(p)

with Flow('Kafka Data Quality Test') as flow:
    full_run = Parameter('full_run', default=False)
    p(full_run)

flow.run(parameters=dict(full_run=True))
will work
a

Alex Post

12/04/2019, 6:23 PM
got it, thanks!
j

josh

12/04/2019, 6:24 PM
Take a look at the section on parameters in this doc if you want more info 🙂 https://docs.prefect.io/core/tutorials/task-guide.html#adding-tasks-to-flows
a

Alex Post

12/04/2019, 6:28 PM
@josh when I try this from that link:
from prefect import Parameter

with Flow("add-example-v3") as f:
    # we will instantiate these Parameters here
    # but note that does NOT add them to the flow yet
    x = Parameter("x", default=1)
    y = Parameter("y", default=2)

    result = add_task(x=x, y=y) # <-- the moment at which x, y are added to the Flow

print(f.tasks) # {<Task: add_task>, <Parameter: y>, <Parameter: x>}

add_task in f.tasks # False
result in f.tasks # True

x in f.tasks # True
y in f.tasks # True
my flow looks like this:
with Flow('Kafka Data Quality Test') as flow:
    # set_envars()
    end_date = datetime.utcnow() - timedelta(hours=2)
    full_run = Parameter('full_run', default=False)
    result = flow.add_task(full_run=full_run)
and I get this error:
Traceback (most recent call last):
  File "src/app.py", line 231, in <module>
    result = flow.add_task(full_run=full_run)
TypeError: add_task() got an unexpected keyword argument 'full_run'
j

josh

12/04/2019, 6:30 PM
Do
add_task(full_run)
,
full_run
isn’t a kwarg of
add_task
as it accepts any task to add to the Flow
a

Alex Post

12/04/2019, 6:32 PM
ah, ok, that did it. thanks!
j

josh

12/04/2019, 6:32 PM
That doc needs to be updated! Thanks for finding this
Oh wait no it doesn’t haha there’s some confusion. That doc creates a task
add_task
which takes in two values and adds them together. Which is different than
flow.add_task
which adds a task to a flow 😄
a

Alex Post

12/04/2019, 6:37 PM
oh I see
that makes sense