fix: validate AlertDto.id as UUID for all providers#6295
Open
nehemiyawicks wants to merge 2 commits intokeephq:mainfrom
Open
fix: validate AlertDto.id as UUID for all providers#6295nehemiyawicks wants to merge 2 commits intokeephq:mainfrom
nehemiyawicks wants to merge 2 commits intokeephq:mainfrom
Conversation
There was a problem hiding this comment.
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_valuessoidis 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.
3edf0a6 to
5ff71f1
Compare
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.
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.idto non-UUID values (numeric IDs, hex fingerprints, alert names, etc.) which causesinvalid input syntax for type uuiderrors when the frontend queries alerts via CEL filters that map to thelastalert.alert_idUUID column. Rather than patching each provider individually, this validates theidfield in the existingroot_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 existingset_default_valuesroot_validator. Valid UUIDs are preserved; non-UUID strings are replaced withuuid.uuid4().tests/test_alert_dto.py: Added 3 test cases covering UUID preservation, non-UUID replacement, and missing ID generation.Test plan
blackandisort