fix(grafana): always set optional alert fields to avoid render_context errors#5658
Open
hakatt wants to merge 1 commit intokeephq:mainfrom
Open
fix(grafana): always set optional alert fields to avoid render_context errors#5658hakatt wants to merge 1 commit intokeephq:mainfrom
hakatt wants to merge 1 commit intokeephq:mainfrom
Conversation
…t errors
Fields like panelUrl, dashboardUrl, silenceURL, valueString, value and
datasource are only present for certain Grafana alert types (webhook vs
datasource). When absent they are missing entirely from the AlertDto
context, causing render_context() to raise a RenderException with
"Could not find key" because it renders all provider with: parameters
using safe=True.
Schema fields defined on AlertDto default to None (Chevron renders None
as "") so they are fine. Extra fields that are never set are genuinely
absent from the context dict, which is what triggers the error.
Fix: always set these optional extra fields (as "" when absent) in both
the webhook alert path and the datasource alert path of the Grafana
provider. Workflow templates can then safely reference them and use
Python or-chains for fallbacks: '{{ alert.panelUrl }}' or 'N/A'.
Fixes keephq#5070
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@nflx is attempting to deploy a commit to the KeepHQ Team on Vercel. A member of the Team first needs to authorize it. |
|
|
Contributor
|
Target branch is not in the allowed branches list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5070 and the general class of
"Could not find key 'alert.X'"errors that occur when a workflow template references an alert field that is absent from the context.Root cause
render_context()iniohandler.pyrenders all providerwith:parameters using Chevron/Mustache withsafe=True. When Chevron encounters{{ alert.someField }}and that field doesn't exist in the alert context dict, it writes"Could not find key alert.someField"to stderr — which_render()detects and raises aRenderException.This affects schema fields and extra fields differently:
AlertDto(e.g.url,description) always exist in the context because they haveNonedefaults — Chevron rendersNoneas"", no error.extra = Extra.allow) that are never set are genuinely absent from the context dict, which triggers the error.For the Grafana provider, several useful fields (
panelUrl,dashboardUrl,silenceURL,valueString,value,datasource) fall into this second category — they're only populated for certain alert types (webhook vs. datasource alerts) and were previously set toNoneor not set at all when absent.Fix
Always set these optional extra fields as
""when absent, in both the webhook alert path (_format_alert) and the datasource alert path (_get_alerts_datasource). Workflow templates can then safely reference them and useor-chains for fallbacks:The same pattern should be applied to other providers where fields are conditionally present. The underlying issue is that
render_context()usessafe=Trueuniformly — a more general fix could be to allow providers or individual parameters to opt out of safe rendering, but that is a larger change.Test plan
panelUrl,dashboardUrl,silenceURL,valueString) — optional fields populated correctlydatasource,value) — webhook-only fields default to""RenderException🤖 Generated with Claude Code