Skip to content

fix(grafana): accept null values/labels/annotations in webhook intake - #99

Closed
lshearing-lavanda wants to merge 1 commit into
roxy-wi:mainfrom
lshearing-lavanda:fix/grafana-null-values
Closed

lshearing-lavanda wants to merge 1 commit into
roxy-wi:mainfrom
lshearing-lavanda:fix/grafana-null-values

Conversation

@lshearing-lavanda

Copy link
Copy Markdown

Fixes #98.

Problem

GrafanaAlertSchema types values (and labels/annotations) as
Dict[str, Any] = Field(default_factory=dict). default_factory only applies
when the key is absent, so an explicit "values": null — which Grafana
Alerting sends for alerts with no reduced numeric values (the contact-point
Test button, and no-data/resolved transitions) — fails validation with
Input should be a valid dictionary. The intake then returns 400 and the
alert is dropped.

Fix

A mode="before" field validator on GrafanaAlertSchema coerces null -> {}
for labels, annotations and values, so these Grafana-native nulls are
accepted while every other input is untouched.

@field_validator("labels", "annotations", "values", mode="before")
@classmethod
def _null_to_empty_dict(cls, value: Any) -> Any:
    return {} if value is None else value

Test

Adds test_grafana_alert_accepts_null_values to
tests/integrations/test_grafana_integration.py, asserting a payload with
values: null normalizes without error and yields values == {}.

Notes

  • Behaviour is unchanged for payloads that already send dicts (real firing
    alerts carry values like {"B": 44.2, "C": 1}).
  • Discovered while wiring Grafana contact points to the IncidentRelay Grafana
    intake: the contact-point "Test" button and no-data transitions were failing
    with the 400 above.

Grafana Alerting sends "values": null (and can send null labels/annotations)
for alerts that carry no reduced numeric values — e.g. the contact-point
"Test" notification and no-data/resolved transitions. GrafanaAlertSchema types
these as Dict[str, Any] with default_factory=dict, but default_factory only
applies when the key is ABSENT; an explicit null fails validation with
"Input should be a valid dictionary", so /api/integrations/grafana returns 400
and the alert is dropped.

Coerce null -> {} via a mode="before" field validator. Adds a regression test.
@Aidaho12 Aidaho12 added the duplicate This issue or pull request already exists label Sep 25, 2026
@Aidaho12

Copy link
Copy Markdown
Member

Hello, and thank you, but it was closed in #94. Will be released with 2.3 in a week

@Aidaho12 Aidaho12 closed this Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grafana webhook intake rejects values: null (Test notifications & no-data alerts fail with 400)

2 participants