Ling Chen
01/14/2022, 5:36 AMcreate_flow_run
in normal python console but not in a python Flask app? The following minimal example will raise AttributeError: 'Context' object has no attribute 'logger'
error. Any ideas?
from flask import Flask
from prefect.tasks.prefect import create_flow_run
app = Flask(__name__)
@app.route("/")
def hello_world():
create_flow_run.run(flow_name="test_flow",
project_name="test_project")
return "<p>Create Prefect Flow Run From Flask!</p>"
Anna Geller
create_flow_run
mutation. However, the p`refect.tasks.create_flow_run` is a normal Prefect tasks which can only be called in an active Flow context, i.e. in a Prefect flow.
To trigger a flow run from Flask, you would need to call the API e.g. using requests:
import requests
create_mutation = """
mutation($input: createFlowRunInput!){
createFlowRun(input: $input){
flow_run{
id
}
}
}
"""
inputs = dict(
versionGroupId="339c86be-5c1c-48f0-b8d3-fe57654afe22", parameters=dict(x=6)
)
response = <http://requests.post|requests.post>(
url="<<https://api.prefect.io>>",
json=dict(query=create_mutation, variables=dict(input=inputs)),
headers=dict(authorization=f"Bearer {API_KEY}"),
)
print(response.status_code)
print(response.text)
Ling Chen
01/14/2022, 4:23 PM