Is there an existing issue for this?
What happened?
While reviewing the database layer, I noticed that the backend/app/database/images.py module defines and uses its own _connect() function instead of the standardized get_db_connection() context manager provided in connection.py.
This creates an inconsistent database access pattern across the backend.
Because _connect() only enables PRAGMA foreign_keys = ON and skips all the other PRAGMAs (recursive triggers, check constraints, deferred FKs, case-sensitive LIKE, etc.), the module bypasses important safety and reliability guarantees that the rest of the codebase relies on.
It also skips the automatic commit/rollback, consistent error handling, and connection lifecycle management built into get_db_connection().
As a result:
- Transactions in images.py behave differently from the rest of the system
- Error states may leave the DB partially committed
- Missing PRAGMAs can cause silent constraint failures
- The logic becomes harder to maintain and reason about
The fix is straightforward:
All usages of _connect() in images.py should be refactored to use get_db_connection() and the _connect() helper should be removed entirely.
This brings the entire database layer back into a single consistent pattern and aligns with the established architecture used across other modules.
Record
Checklist before Submitting
Is there an existing issue for this?
What happened?
While reviewing the database layer, I noticed that the backend/app/database/images.py module defines and uses its own _connect() function instead of the standardized get_db_connection() context manager provided in connection.py.
This creates an inconsistent database access pattern across the backend.
Because _connect() only enables PRAGMA foreign_keys = ON and skips all the other PRAGMAs (recursive triggers, check constraints, deferred FKs, case-sensitive LIKE, etc.), the module bypasses important safety and reliability guarantees that the rest of the codebase relies on.
It also skips the automatic commit/rollback, consistent error handling, and connection lifecycle management built into get_db_connection().
As a result:
The fix is straightforward:
All usages of _connect() in images.py should be refactored to use get_db_connection() and the _connect() helper should be removed entirely.
This brings the entire database layer back into a single consistent pattern and aligns with the established architecture used across other modules.
Record
Checklist before Submitting