Fix: Narrow except Exception to except SQLAlchemyError in health_check()#941
Fix: Narrow except Exception to except SQLAlchemyError in health_check()#941Bornunique911 wants to merge 2 commits into
Conversation
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughIn ChangesHealth Check Exception Narrowing
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Fixes overly broad exception handling in
Node_collection.health_check()by replacingexcept Exceptionwithexcept SQLAlchemyError.Closes #940
Problem
The
health_check()method inapplication/database/db.pycurrently uses a genericexcept Exceptionas a fallback after catchingOperationalError:This broad catch silently swallows programming bugs such as AttributeError, TypeError, or NameError within the health check logic itself. Instead of propagating the error (which would reveal the bug), it returns a structured {"ok": False} response, making such issues very hard to detect.
Solution
Add
SQLAlchemyErrorto the import fromsqlalchemy.excReplace
except Exception:withexcept SQLAlchemyError:.Since OperationalError is a subclass of SQLAlchemyError and is caught first, the new clause only handles remaining SQLAlchemy-level errors.
Changes
File:
application/database/db.pyChange 1 – Import (line ~26):
Change 2 – Exception handler (lines ~2292–2296):
Behavioral Change
In production, this means:
Before: Any unexpected error →
{"ok": False, ...}(bug hidden)After: SQLAlchemy errors →
{"ok": False, ...}; programming bugs → HTTP 500 with stack trace (bug visible)Related Issue
Closes #940