fix(ui): use name instead of id in workflow execution triggered-by alert CEL filter#6236
Open
ahbeigi wants to merge 2 commits intokeephq:mainfrom
Open
fix(ui): use name instead of id in workflow execution triggered-by alert CEL filter#6236ahbeigi wants to merge 2 commits intokeephq:mainfrom
ahbeigi wants to merge 2 commits intokeephq:mainfrom
Conversation
When a CEL filter contains a non-UUID value against a UUID-typed column, PostgreSQL raises a DataError which was not caught — only CelToSqlException was handled, so FastAPI returned a 500. Add an explicit except DataError block that returns a 400 with a clear message. This is a provider-agnostic safety net: any provider that stores a non-UUID alert id would hit the same crash, regardless of fixes applied at the provider level. Related: keephq#6219 (fixes root cause in Prometheus provider).
d302e3e to
4969ada
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.
Based on the suggestion in #6237, this PR was repurposed from the original frontend fix to instead add a defensive
DataErrorhandler at the/alerts/queryAPI layer.The root cause is that the Prometheus provider stores
alertnameas the alertidinstead of a UUID (tracked in #6219). The workflow scheduler embeds this non-UUID string intotriggered_by, the frontend builds a CEL filterid=="<alertname>", and the backend mapsidtolastalert.alert_id(a UUID column). PostgreSQL rejects the query withinvalid input syntax for type uuid— thisDataErrorwas not caught, so FastAPI returned a500.PR #6219 fixes this at the provider level. This PR adds a complementary safety net at the API layer so any provider storing a non-UUID alert
idreturns a400with a clear message instead of an unhandled500, regardless of whether #6219 has been merged.Closes #6237
📑 Description
keep/api/routes/alerts.py: addexcept DataErrorinquery_alertsalongside the existingexcept CelToSqlException, returning400instead of500✅ Checks
ℹ Additional Information
Before: any CEL query containing a non-UUID value against a UUID-typed column causes an unhandled
DataError→500 An internal server error occurred. URL: /alerts/query.After: the same query returns
400 Invalid value in query - a field may contain a non-UUID valuewith the offending CEL expression in the response detail.No breaking changes. No new dependencies. Related: #6219.
Note
Low Risk
Low risk: small, localized error-handling change that only alters the HTTP response for previously-unhandled database type errors (500 -> 400) when running alert queries.
Overview
Prevents
/alerts/queryfrom returning an unhandled 500 when a CEL filter supplies an invalid value for a UUID-typed field.query_alertsnow catches SQLAlchemyDataErrorand returns a 400 with a clearer message (including the offending CEL expression), alongside the existingCelToSqlExceptionhandling.Reviewed by Cursor Bugbot for commit dd88610. Bugbot is set up for automated code reviews on this repo. Configure here.