Have a problem triggering flow-runs from completed...
# prefect-community
s
Have a problem triggering flow-runs from completed flows with variable parameters passed. I can trigger the flows just fine, but the parameters are not getting passed correctly. Can you share the code syntax to trigger a new flow with parameters using
prefect<2.0
and the functional API? I will share the pseudo-code and syntax in a reply.
1
Copy code
import prefect
from prefect.tasks.prefect import create_flow_run

def get_update_date():
    return '2022-01-01'

def trigger_flow(**kwargs):
    create_flow_run.run(
        flow_name='flow-2'
        project_name='test',
        parameters={'update_date': kwargs.get('update_date')}
    )

get_update_date = prefect.task(get_update_date)
trigger_flow = prefect.task(trigger_flow)

with prefect.Flow('flow-1') as flow:
    update_date = get_update_date()
    trigger_flow(update_date=update_date)
Flow 2:
Copy code
import prefect

update_date = prefect.Parameter('update_date', default=None)

def print_date(update_date):
   prefect.logger(f'{update_date}')

print_date = prefect.task(print_date)

with prefect.Flow('flow-2') as flow:
    print_date()
In this case, the flow-2 will print
None
when it is triggered by
flow-1
but if I trigger
flow-2
manually with a hard-coded
update_date
it will print just fine
j
Tasks need to be called within Flows. This example and this thread and associated resources might be helpful.