<@ULVA73B9P> in prefect 3.2.8 I'm creating an auto...
# ask-marvin
m
@Marvin in prefect 3.2.8 I'm creating an automation to send notification to my custom webserver. In the automation I have the body like this: Flow run {{ flow.name }}/{{ flow_run.name }} observed in state
{{ flow_run.state.name }}
at {{ flow_run.state.timestamp }}. Flow ID: {{ flow_run.flow_id }} Flow run ID: {{ flow_run.id }} Flow run URL: {{ flow_run|ui_url }} State message: {{ flow_run.state.message }} while in the block I left the body empty. On my webserver I'm getting an empty body.
m
It seems you're having trouble with Prefect 3.2.8 automation templates, specifically when sending notifications to your custom webserver. Here are some insights that might help: 1. Template Rendering: Prefect uses Jinja2 for template rendering. Ensure that your template produces a valid JSON object. The output of your template should be a valid string that can be parsed, for example, with
json.loads
. This is crucial for the automation to work correctly. Documentation Reference 2. Template Variables: Double-check the variables you're using in the template. Make sure they are correctly defined and available in the context where the template is rendered. Prefect's documentation doesn't list any specific issues with these variables, but ensuring they are correct and available is essential. 3. Empty Body Issue: There are no open GitHub issues specifically mentioning an empty body for notifications. This might indicate a configuration or rendering issue unique to your setup. 4. Prefect Variables: If you're using Prefect variables in your template, ensure they are correctly set and retrieved. Prefect variables are dynamically-named, mutable string values. They are not meant for sensitive data and should be used for configuration information. Documentation Reference If you continue to experience issues, consider reviewing your template syntax and ensure that all variables are correctly passed and rendered. If the problem persists, it might be worth checking Prefect's GitHub for any updates or similar issues reported by other users.
m
should I add a body in my custom block like this one? { "flow_name": "{{ flow.name }}", "flow_run_name": "{{ flow_run.name }}", "state": "{{ flow_run.state.name }}", "timestamp": "{{ flow_run.state.timestamp }}", "flow_id": "{{ flow_run.flow_id }}", "flow_run_id": "{{ flow_run.id }}", "flow_run_url": "{{ flow_run|ui_url }}", "state_message": "{{ flow_run.state.message }}" }
@Marvin should I add a body in my custom block like this one? { "flow_name": "{{ flow.name }}", "flow_run_name": "{{ flow_run.name }}", "state": "{{ flow_run.state.name }}", "timestamp": "{{ flow_run.state.timestamp }}", "flow_id": "{{ flow_run.flow_id }}", "flow_run_id": "{{ flow_run.id }}", "flow_run_url": "{{ flow_run|ui_url }}", "state_message": "{{ flow_run.state.message }}" }
m
Yes, defining a body like the one you've suggested is a good approach. It ensures that the notification sent to your custom webserver is structured as a valid JSON object, which is essential for proper parsing and handling on the receiving end. Here's how your JSON body looks:
Copy code
json
{
  "flow_name": "{{ flow.name }}",
  "flow_run_name": "{{ flow_run.name }}",
  "state": "{{ flow_run.state.name }}",
  "timestamp": "{{ flow_run.state.timestamp }}",
  "flow_id": "{{ flow_run.flow_id }}",
  "flow_run_id": "{{ flow_run.id }}",
  "flow_run_url": "{{ flow_run|ui_url }}",
  "state_message": "{{ flow_run.state.message }}"
}
Make sure to: 1. Validate JSON: Ensure that the JSON format is correct and that all placeholders are available in the context where the template is rendered. 2. Check Variables: Double-check that all variables (
flow
,
flow_run
, etc.) are correctly defined and accessible in your Prefect environment. 3. Use Jinja2: Remember that Prefect uses Jinja2 for rendering, so all standard Jinja2 syntax and features are available. By defining your body in this structured manner, you should be able to resolve the issue of receiving an empty body on your webserver.
m
@Marvin 084731.608 | WARNING | prefect.server.events.actions - Action failed: 'The notification block was invalid: 1 validation error for CustomWebhookNotificationBlock\njson_data\n Input should be a valid dictionary [type=dict_type, input_value=\'{\\n "flow_name": "{{ fl...un.state.message }}"\\n}\', input_type=str]\n For further information visit https://errors.pydantic.dev/2.10/v/dict_type'
m
The error message you're encountering indicates that the JSON data for the
CustomWebhookNotificationBlock
is being treated as a string rather than a dictionary, which is required for validation. Here's how you can address this: 1. Ensure JSON Format: Make sure that your JSON body is correctly defined as a dictionary. The error suggests that it is being interpreted as a string. You might need to adjust how the JSON is being passed or rendered in your code. 2. Use Jinja2 Correctly: When using Jinja2 for rendering the JSON, ensure that the output is a valid dictionary. The rendered output should not be a string representation of the dictionary but an actual dictionary object. 3. Check Serialization: Prefect uses serializers to convert objects to and from bytes. Ensure that the JSON data is correctly serialized into a dictionary before it is passed to the
CustomWebhookNotificationBlock
. 4. Prefect Blocks Documentation: You can refer to the Prefect Blocks Documentation for more details on how to correctly configure and use blocks like the
CustomWebhookNotificationBlock
. If you continue to face issues, consider checking how the JSON data is being constructed and passed in your automation script to ensure it aligns with the expected dictionary format.