Skip to content

Improve SQLAlchemy API usage and db session management #4749

@itallix

Description

@itallix

Refactor the project’s SQLAlchemy integration to align with best practices and the latest API standards.

Acceptance Criteria:

  • Session factory improvements: update SessionLocal to use autoflush=True behavior by default to reduce boilerplate.
  • Session DI: define db_session as a dependency and inject into services. (this will help to avoid monkeypatching in tests)
  • No caching for stateless services: most of the services are stateless, we can avoid using @lru_cache with it.
  • Upgrade to the latest 2.0 SQLAlchemy API:
    • Identify and refactor all usages of legacy SQLAlchemy APIs (e.g., db.query) to use the recommended modern API (e.g., db.execute(select(...)))
    • Update repository code and ensure all queries use the latest patterns.
  • Testing improvements: review unit tests and replace monkeypatching of database/session logic with dependency injection or fixtures where possible.

Metadata

Metadata

Assignees

Labels

Geti Tune BackendIssues related to Geti Tune Studio backendpythonPull requests that update Python code

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions