Skip to content

fix: validate AlertDto.id as UUID for all providers#6295

Open
nehemiyawicks wants to merge 2 commits intokeephq:mainfrom
nehemiyawicks:fix/alert-id-uuid-validation
Open

fix: validate AlertDto.id as UUID for all providers#6295
nehemiyawicks wants to merge 2 commits intokeephq:mainfrom
nehemiyawicks:fix/alert-id-uuid-validation

Conversation

@nehemiyawicks
Copy link
Copy Markdown

@nehemiyawicks nehemiyawicks commented Apr 25, 2026

Closes #6237 (partially -- prevents the 500 at the data layer)
Related to #6219 (extends the Prometheus-specific fix to all providers)

Summary

Extends the fix from #6219 (Prometheus-specific) to all providers by adding centralized UUID validation in AlertDto.set_default_values.

32+ providers set AlertDto.id to non-UUID values (numeric IDs, hex fingerprints, alert names, etc.) which causes invalid input syntax for type uuid errors when the frontend queries alerts via CEL filters that map to the lastalert.alert_id UUID column. Rather than patching each provider individually, this validates the id field in the existing root_validator -- non-UUID values are replaced with a generated UUID, matching the try/except pattern from #6219.

Affected providers include: Grafana (6 locations), Datadog, PagerDuty, Zabbix, Dynatrace, NewRelic, Sentry, Splunk, CloudWatch, Checkly, Centreon, GCP Monitoring, iLert, Rollbar, StatusCake, ThousandEyes, Pingdom, UptimeKuma, and more.

Changes

  • keep/api/models/alert.py: Added UUID validation in the existing set_default_values root_validator. Valid UUIDs are preserved; non-UUID strings are replaced with uuid.uuid4().
  • tests/test_alert_dto.py: Added 3 test cases covering UUID preservation, non-UUID replacement, and missing ID generation.

Test plan

  • Unit tests pass for valid UUID preservation
  • Unit tests pass for non-UUID replacement (numeric, hex, string, negative numbers)
  • Unit tests pass for missing ID generation
  • Formatted with black and isort
  • CI tests

Copilot AI review requested due to automatic review settings April 25, 2026 17:07
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 25, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 25, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Centralizes AlertDto.id UUID validation to prevent database query failures caused by providers emitting non-UUID alert IDs (e.g., numeric IDs, fingerprints, alert names), extending the prior Prometheus-only fix to all providers.

Changes:

  • Add UUID validation/generation in AlertDto.set_default_values so id is always a valid UUID string.
  • Add unit tests ensuring valid UUIDs are preserved, non-UUID IDs are replaced, and missing IDs get generated.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
keep/api/models/alert.py Enforces UUID-compatible AlertDto.id in the existing root_validator by validating and generating UUIDs when needed.
tests/test_alert_dto.py Adds coverage for UUID preservation, replacement of non-UUID IDs, and UUID generation when id is missing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Extends the fix from keephq#6219 (Prometheus) to all providers centrally.
Many providers set AlertDto.id to non-UUID values (numeric IDs,
fingerprints, alert names, etc.) which causes "invalid input syntax
for type uuid" errors when the frontend queries alerts via CEL filters
that map to the lastalert.alert_id UUID column.

Instead of patching each provider individually (32+ affected), add UUID
validation in the existing AlertDto root_validator. Non-UUID values are
replaced with a generated UUID, matching the pattern established in
keephq#6219.

Affected providers include: Grafana, Datadog, PagerDuty, Zabbix,
Dynatrace, NewRelic, Sentry, Splunk, CloudWatch, Checkly, and many
more.
@nehemiyawicks nehemiyawicks force-pushed the fix/alert-id-uuid-validation branch from 3edf0a6 to 5ff71f1 Compare April 25, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Workflow execution triggered-by alert link returns 500

4 participants