Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

chore: add Session type hints to db_session parameters across remaining files (#4487)

LearningCircuit346ed9c0ea0f
diff --git a/src/local_deep_research/news/web.py b/src/local_deep_research/news/web.py
index 79a3716569..608b3fe203 100644
--- a/src/local_deep_research/news/web.py
+++ b/src/local_deep_research/news/web.py
@@ -4,6 +4,8 @@ Flask blueprint for news system web routes.
from flask import Blueprint, jsonify, render_template
from loguru import logger
+from sqlalchemy.orm import Session
+from typing import Optional
from ..constants import get_available_strategies
from ..web.auth.decorators import login_required
@@ -176,7 +178,9 @@ def create_news_blueprint():
return bp
-def load_user_settings(default_settings, db_session=None, username=None):
+def load_user_settings(
+ default_settings, db_session: Optional[Session] = None, username=None
+):
"""
Load user settings and update default_settings dictionary.
Extracted to avoid code duplication as suggested by djpetti.
diff --git a/src/local_deep_research/web/auth/decorators.py b/src/local_deep_research/web/auth/decorators.py
index 81539c3104..f8f62aa1e2 100644
--- a/src/local_deep_research/web/auth/decorators.py
+++ b/src/local_deep_research/web/auth/decorators.py
@@ -3,9 +3,11 @@ Authentication decorators for protecting routes.
"""
from functools import wraps
+from typing import Optional
from flask import g, jsonify, redirect, request, session, url_for
from loguru import logger
+from sqlalchemy.orm import Session
from ...database.encrypted_db import db_manager
from ...security.url_validator import URLValidator
@@ -84,7 +86,7 @@ def current_user():
return session.get("username")
-def get_current_db_session():
+def get_current_db_session() -> Optional[Session]:
"""
Get the database session for the current user.
Must be called within a login_required route.
diff --git a/src/local_deep_research/web/queue/processor_v2.py b/src/local_deep_research/web/queue/processor_v2.py
index 54691f9853..2220b61828 100644
--- a/src/local_deep_research/web/queue/processor_v2.py
+++ b/src/local_deep_research/web/queue/processor_v2.py
@@ -9,6 +9,7 @@ import uuid
from typing import Any, Dict, Optional
from loguru import logger
+from sqlalchemy.orm import Session
from ...constants import ResearchStatus
from ...database.encrypted_db import db_manager
@@ -134,7 +135,7 @@ class QueueProcessorV2:
return attempts
@staticmethod
- def _commit_with_safe_rollback(db_session, context: str) -> bool:
+ def _commit_with_safe_rollback(db_session: Session, context: str) -> bool:
"""Commit ``db_session`` with best-effort rollback on failure.
Returns ``True`` on success, ``False`` if the commit raised.
@@ -822,7 +823,9 @@ class QueueProcessorV2:
)
return False # Keep checking - errors might be temporary
- def _reclaim_stranded_queue_rows(self, db_session, username: str) -> int:
+ def _reclaim_stranded_queue_rows(
+ self, db_session: Session, username: str
+ ) -> int:
"""Reclaim queue rows stranded by a crash or restart.
A row is stranded when ``is_processing=True`` but no live thread
diff --git a/src/local_deep_research/web/services/research_sources_service.py b/src/local_deep_research/web/services/research_sources_service.py
index cbbf5b9470..7c73fe666c 100644
--- a/src/local_deep_research/web/services/research_sources_service.py
+++ b/src/local_deep_research/web/services/research_sources_service.py
@@ -10,7 +10,7 @@ from datetime import datetime, UTC
from loguru import logger
from sqlalchemy import or_
from sqlalchemy.exc import IntegrityError
-from sqlalchemy.orm import load_only
+from sqlalchemy.orm import Session, load_only
from ...database.models import (
Journal,
@@ -482,7 +482,9 @@ def _resolve_journal_id(
return row[0] if row else None
-def _find_existing_paper(db_session, fields: dict) -> Optional["Paper"]:
+def _find_existing_paper(
+ db_session: Session, fields: dict
+) -> Optional["Paper"]:
"""Find an existing Paper by any of DOI, arXiv ID, or PMID.
Issues a single OR-query across all provided identifiers so that a