Skip to content

Database Connection Inconsistency #641

@srijan2607

Description

@srijan2607

Is there an existing issue for this?

  • I have searched the existing issues

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

  • I agree to follow this project's Code of Conduct

Checklist before Submitting

  • Have you updated docs for it?
  • Have you added unit tests?
  • Have you made sure unit tests pass?
  • Have you made sure code formatting is correct?
  • Do Your changes passes all tests?

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions