Hi - I'm having an issue with setting a parameter ...
# prefect-community
a
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:
Copy code
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:
Copy code
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
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.
Copy code
@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
got it, thanks!
j
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
@josh when I try this from that link:
Copy code
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:
Copy code
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:
Copy code
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
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
ah, ok, that did it. thanks!
j
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
oh I see
that makes sense