Fix: wrap SELECT 1 in text() for SQLAlchemy 2.x compatibility (#154) - #446
Open
laurale31 wants to merge 12 commits into
Open
Fix: wrap SELECT 1 in text() for SQLAlchemy 2.x compatibility (#154)#446laurale31 wants to merge 12 commits into
laurale31 wants to merge 12 commits into
Conversation
Removed redundant links and sections from JOURNAL.md.
laurale31
marked this pull request as ready for review
July 31, 2026 02:24
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
Fixes the
/healthendpoint's Postgres check, which currently reports the database as unhealthy even when it's fully reachable. The root cause is that SQLAlchemy 2.x no longer accepts raw SQL strings passed directly toexecute()— they must be explicitly wrapped insqlalchemy.text(). This PR wraps the query so the health check accurately reflects the database's real status.Issue
Closes #154
Changes
textfromsqlalchemyinapi/routes/health.pydb.execute("SELECT 1")→db.execute(text("SELECT 1"))tests/unit/test_health.pywith two tests covering the Postgres check's healthy and unhealthy pathsTesting
make test-unit) — see note below on pre-existing failuresmake test-integration) — not applicable to this fix; no integration tests touch this routemake lint) — see note below on pre-existing failuresmake typecheck) — see note below on pre-existing failuresManual verification:
docker compose up -dto start Postgres and Redis.make runto start the app.curl http://localhost:8000/health— before this fix, the response shows"postgres": "unhealthy"with anArgumentErrorin the server logs; after this fix, it shows"postgres": "healthy".pytest tests/unit/test_health.py -vto confirm the new unit tests pass (2 passed).Screenshots / Demo
N/A — this is a backend API fix; verification steps above cover the change.
Notes for Reviewers
This PR only touches the Postgres check in
health_check(). The Redis check in the same function is separately broken (see #155, an invalidsettings.redis_hostreference) — that's out of scope here and left untouched. In fact, it's relied upon intest_postgres_check_healthy_when_query_succeedsto confirm the Postgres check is correctly isolated from that failure (i.e.,health_check()still raisesHTTPExceptionoverall due to Redis, but the Postgres field in the payload correctly reports "healthy").Pre-existing failures (confirmed via
git stashbaseline comparison before my changes):ruff check api/routes/health.py: 1 pre-existing issue (B008,Dependsin default arg) — present before my change, unrelated to it.mypy api/routes/health.py: 11 pre-existing errors (missing type annotations, dict indexing on untyped object, Redis config type mismatches, and the Health check referencessettings.redis_host, which does not exist on Settings #155redis_host/redis_portattribute errors) — all present before my change.make test-unit: 53 pre-existing test failures across 16 files (e.g.test_pii_scrubber.py,test_relevance_scorer.py,test_tech_detector.py,test_resume_parser.py), corresponding to other known open issues on the tracker. My change adds 2 new passing tests and does not affect this failure count (375 → 377 passed, 53 failed both before and after my change).My changes introduce no new lint, type-check, or test failures beyond this documented baseline.