Repository navigation
fix(api): count alerts from organization_alerts in /api/runs/stats - #144
Merged
Goldokpa merged 1 commit intoNov 25, 2026
Merged
Conversation
GET /api/runs/stats counted unacknowledged alerts with "SELECT COUNT(*) FROM alerts WHERE acknowledged = 0", but the legacy alerts table has no acknowledged column, so the endpoint failed with "sqlite3.OperationalError: no such column: acknowledged" and a 500 on every database, empty or not. Alerts are created, listed and acknowledged in organization_alerts, and nothing writes to the legacy table, so both alert counts now come from organization_alerts. The new tests run against a temporary database: the stats of an empty database, the alert counts with one of three alerts acknowledged, and the run counts by status, by analysis type and over the last 7 days. All three fail without the fix.
Member
|
Thanks @Ayomipo18, good catch. The endpoint has been returning a 500 since it was added, and nothing covered it. Counting from |
Ayomipo18
added a commit
to Ayomipo18/ClimateVision
that referenced
this pull request
Nov 25, 2026
Brings in Climate-Vision#144. Its fix to get_run_stats, which now counts alerts from organization_alerts, is applied in routes/runs.py, where the endpoint moved to; main.py keeps the refactored version.
6 of 14 tasks
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
GET /api/runs/statsreturned a 500 on every database, because it counted unacknowledged alerts in the legacyalertstable, which has noacknowledgedcolumn. Alerts are created, listed and acknowledged inorganization_alerts, and nothing writes to the legacy table, so both alert counts now come fromorganization_alerts.Related Issue
Closes #143
Type of Change
Key Changes
get_run_statscountsalerts.totalandalerts.unacknowledgedfromorganization_alerts. The response shape is unchanged.tests/test_run_stats.py. The endpoint had no tests. These run against a temporary database, so the counts are exact and the sharedoutputs/database is left alone:total: 3, unacknowledged: 2,Testing
pytest tests/): 234 passed, 1 skipped, on both Python 3.9 / FastAPI 0.128 and Python 3.11 / FastAPI 0.165. The one failure,test_onnx_inference.py::test_run_inference_reports_backend_and_latency, fails the same way onmainlocally (no ONNX runtime).TestClient.npm run dev): no frontend change.mainwithsqlite3.OperationalError: no such column: acknowledgedand pass with the fix.flake8 src/ --select=E9,F63,F7,F82reports 0, and the new test file is black-clean.With #142: this touches the same lines that #142 moves to
routes/runs.py, so whichever merges second needs a small rebase. I'll do it on #142 if this one goes in first.Checklist
developbranch (notmain): it targetsmain, where docs: remove references to nonexistent requirements-dev.txt #123, test(frontend): add Vitest + React Testing Library suite (#9) #125 and Add: WebSocket endpoint for real-time run status (#11) #140 were merged, since there is nodevelopbranch anymore