Skip to content

fix(db): fix health_check coroutine and raw SQL string#63

Merged
RegardV merged 1 commit intomainfrom
production-inkypyrus
Feb 22, 2026
Merged

fix(db): fix health_check coroutine and raw SQL string#63
RegardV merged 1 commit intomainfrom
production-inkypyrus

Conversation

@RegardV
Copy link
Owner

@RegardV RegardV commented Feb 22, 2026

User description

Summary

  • Fixes RuntimeWarning: coroutine 'DatabaseManager.get_session' was never awaited in backend logs
  • async with self.get_session() was using a coroutine as a context manager — replaced with self.session_factory() directly
  • Wraps raw "SELECT 1" with text() for SQLAlchemy 2.0 compatibility

Result

Backend startup logs are now clean — no warnings.

🤖 Generated with Claude Code


PR Type

Bug fix


Description

  • Fixes RuntimeWarning by replacing coroutine with session factory

  • Wraps raw SQL string with text() for SQLAlchemy 2.0 compatibility

  • Eliminates backend startup log warnings


Diagram Walkthrough

flowchart LR
  A["health_check method"] -->|"Replace async with"| B["self.session_factory()"]
  A -->|"Wrap SQL with"| C["text() function"]
  B -->|"Result"| D["No RuntimeWarning"]
  C -->|"Result"| D
Loading

File Walkthrough

Relevant files
Bug fix
database.py
Fix health_check coroutine and SQL string issues                 

journal-platform-backend/app/core/database.py

  • Replaced async with self.get_session() with async with
    self.session_factory() to avoid coroutine RuntimeWarning
  • Wrapped raw SQL string "SELECT 1" with text() for SQLAlchemy 2.0
    compatibility
  • Added import statement for text from sqlalchemy module
+3/-3     

- Replace 'async with self.get_session()' with 'async with self.session_factory()'
  to avoid RuntimeWarning: coroutine was never awaited
- Wrap raw SQL with text() for SQLAlchemy 2.0 compatibility

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@RegardV RegardV merged commit 46749dc into main Feb 22, 2026
3 of 7 checks passed
@qodo-code-review
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Verify health check response

Improve the health check by using session.scalar() to fetch the query result and
confirm it equals 1.

journal-platform-backend/app/core/database.py [119]

-await session.execute(text("SELECT 1"))
+value = await session.scalar(text("SELECT 1"))
+if value != 1:
+    raise RuntimeError(f"Unexpected health check result: {value}")
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This suggestion correctly improves the health check's robustness by not only executing a query but also verifying its result, ensuring the database connection is fully functional.

Medium
Move import to module-level

Move the from sqlalchemy import text statement to the top of the file with other
module-level imports.

journal-platform-backend/app/core/database.py [116]

+# at the top of file, alongside other imports
 from sqlalchemy import text
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly points out that the text import, added within a method, should be moved to the module level to adhere to Python's best practices and avoid repeated imports.

Low
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant