<@ULVA73B9P> I'm handling flow failures with an au...
# ask-marvin
j
@Marvin I'm handling flow failures with an automation and I want to send a message to MS Teams that includes the flow run's URL. however, using this template
{{ flow_run|ui_url }}
always returns None. how can I get the flow run URL?
m
To assist you better, I need to determine which version of Prefect you are using because the method to get the flow run's URL might vary between versions 2.x and 3.x. Do you know which version you are working with? If not, I can check both versions for possible solutions.
j
3.x prefect server
3.0.4
still there?
@Marvin prefect server 3.0.4
m
To send a message to Microsoft Teams that includes the flow run's URL using Prefect 3.0.4, you might encounter issues with templating that need specific attributes. Based on the documentation, using the
flow_run|ui_url
template variable directly might not work if it's not properly defined in the template context. You can, however, manually construct the URL by embedding the flow run ID in the URL pattern your Prefect server uses. Typically, the URL for a flow run on Prefect's UI can be constructed like this:
Copy code
<https://your-prefect-server/orm/flow-run/{flow_run.id}>
To incorporate this into your automation Jinja template, you can use:
Copy code
Flow Run URL: <https://your-prefect-server/orm/flow-run/{{> flow_run.id }}
Make sure to replace
your-prefect-server
with the actual URL of your Prefect server. This way, you ensure you are dynamically generating the correct link to each flow run based on the ID. You can find more details about automations and templating in Prefect 3.0.4 here.
j
@Marvin how to ensure that it's properly defined in the template context?
m
To ensure the flow run URL is properly defined in the template context when using Prefect automations, you need to ensure that the required attributes are included in the context provided to the template. Here’s how you can typically ensure proper context setup: 1. Retrieve Flow Run Details: Make sure your automation setup retrieves all necessary details of a flow run, such as its ID. Prefect provides access to various properties of flow runs, but you need to ensure they are available as part of the context when the template is processed. 2. Template Syntax: Use correct Jinja2 templating syntax by wrapping variable names in double curly brackets, e.g.,
{{ flow_run.id }}
. For URLs, manually construct the path using these templates to dynamically substitute the ID into your Prefect UI URL string. 3. Access to Context Variables: Verify that your automation or trigger has access to the full context of the flow run. You may need to customize or extend the triggers in a way that ensures
flow_run
and its properties like
id
are part of what is passed to templates. 4. Custom Automation Setup: If your current automation doesn’t implicitly make all flow run details available, you might need to enhance how automations are set up, potentially involving creating custom triggers or actions that more directly inject these variables into your template context. For specific steps on including additional information into automations or extending automation capabilities, refer to Prefect 3.0 Automations Documentation. This will provide detailed instructions on how to work with variables in automation contexts. If you need further detail about adjusting template execution or improving automation setups, feel free to ask!