It seems that I can call `create_flow_run` in norm...
# ask-community
l
It seems that I can call
create_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?
Copy code
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>"
a
@Ling Chen Your approach is correct in the sense that you need to trigger the
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:
Copy code
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)
l
Gotcha. Will try this out. Thanks!
👍 1