~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(news): repair subscription-history and organized-subscriptions 500s (#4588)
LearningCircuitb5f55f38ea9c
diff --git a/changelog.d/4588.bugfix.md b/changelog.d/4588.bugfix.mdnew file mode 100644index 0000000000..f2de7247fb--- /dev/null+++ b/changelog.d/4588.bugfix.md@@ -0,0 +1 @@+Fixed two news endpoints that returned HTTP 500 for any real subscription: the subscription history modal (it read a non-existent `refresh_count` column; the run count is now derived from research history) and the organized-subscriptions view (it called `.to_dict()` on plain dicts; it now returns the folder-grouped shape the UI renders).diff --git a/src/local_deep_research/news/api.py b/src/local_deep_research/news/api.pyindex aae5d86aee..8ce7db738b 100644--- a/src/local_deep_research/news/api.py+++ b/src/local_deep_research/news/api.py@@ -491,7 +491,9 @@ def get_subscription_history("query_or_topic": subscription.query_or_topic,"subscription_type": subscription.subscription_type,"refresh_interval_minutes": subscription.refresh_interval_minutes,- "refresh_count": subscription.refresh_count or 0,+ # refresh_count is derived from the actual research-run history+ # below (NewsSubscription has no refresh_count column — reading+ # it raised AttributeError and 500'd this endpoint)."created_at": subscription.created_at.isoformat()if subscription.created_atelse None,@@ -585,6 +587,10 @@ def get_subscription_history(processed_history.append(processed_item)+ # Run count comes from the research history (the source of truth);+ # the subscription row carries no counter.+ subscription_dict["refresh_count"] = len(processed_history)+return {"subscription": subscription_dict,"history": processed_history,diff --git a/src/local_deep_research/news/flask_api.py b/src/local_deep_research/news/flask_api.pyindex 0002402e5b..bd8627c7a5 100644--- a/src/local_deep_research/news/flask_api.py+++ b/src/local_deep_research/news/flask_api.py@@ -1332,10 +1332,25 @@ def get_subscriptions_organized():manager = FolderManager(session)organized = manager.get_subscriptions_by_folder(user_id)- # Convert to JSON-friendly format+ # get_subscriptions_by_folder already returns JSON-friendly dicts+ # ({"folders": [{"folder": {...}, "subscriptions": [...]}, ...],+ # "uncategorized": [...]}). The previous code called .to_dict() on+ # those plain dicts (AttributeError -> HTTP 500). Flatten into the+ # {folder_name: [subscription, ...]} map the subscriptions UI+ # consumes (Object.values(...) for the "all" view, keyed lookup per+ # folder), with ungrouped subscriptions under "uncategorized".result = {}- for folder, subs in organized.items():- result[folder] = [sub.to_dict() for sub in subs]+ for entry in organized.get("folders", []):+ folder_name = entry["folder"].get("name") or entry[+ "folder"+ ].get("id")+ result[folder_name] = entry["subscriptions"]+ # Merge (don't overwrite) so a user folder literally named+ # "uncategorized" doesn't have its subscriptions dropped by the+ # ungrouped bucket. In the normal case this just sets the key.+ result.setdefault("uncategorized", []).extend(+ organized.get("uncategorized", [])+ )return jsonify(result)diff --git a/tests/news/test_flask_api_coverage.py b/tests/news/test_flask_api_coverage.pyindex b3eda7a00c..7f2b2ac192 100644--- a/tests/news/test_flask_api_coverage.py+++ b/tests/news/test_flask_api_coverage.py@@ -748,12 +748,55 @@ class TestSubscriptionStats:class TestGetSubscriptionsOrganized:def test_success(self, client):+ """Returns the flattened {folder_name: [subscription, ...]} map.++ get_subscriptions_by_folder returns plain dicts in a+ {"folders": [...], "uncategorized": [...]} shape; the route must+ flatten them. (The previous version called .to_dict() on those plain+ dicts and 500'd; this also pins that regression.)+ """_auth(client)ctx, _ = _mock_db_session()- so = MagicMock()- so.to_dict.return_value = {"id": "s1"}mm = MagicMock()- mm.get_subscriptions_by_folder.return_value = {"General": [so]}+ mm.get_subscriptions_by_folder.return_value = {+ "folders": [+ {+ "folder": {"id": "f1", "name": "General"},+ "subscriptions": [{"id": "s1", "query_or_topic": "q1"}],+ },+ ],+ "uncategorized": [{"id": "s2", "query_or_topic": "q2"}],+ }+ with (+ patch(f"{MODULE}.get_user_id", return_value="testuser"),+ patch(f"{MODULE}.get_user_db_session", return_value=ctx),+ patch(f"{MODULE}.FolderManager", return_value=mm),+ ):+ resp = client.get("/news/api/subscription/subscriptions/organized")+ assert resp.status_code == 200+ data = resp.get_json()+ assert data["General"] == [{"id": "s1", "query_or_topic": "q1"}]+ assert data["uncategorized"] == [+ {"id": "s2", "query_or_topic": "q2"}+ ]++ def test_folder_named_uncategorized_does_not_drop_subscriptions(+ self, client+ ):+ """A user folder literally named "uncategorized" must not have its+ subscriptions clobbered by the ungrouped bucket — both are merged."""+ _auth(client)+ ctx, _ = _mock_db_session()+ mm = MagicMock()+ mm.get_subscriptions_by_folder.return_value = {+ "folders": [+ {+ "folder": {"id": "f1", "name": "uncategorized"},+ "subscriptions": [{"id": "folder_sub"}],+ },+ ],+ "uncategorized": [{"id": "ungrouped_sub"}],+ }with (patch(f"{MODULE}.get_user_id", return_value="testuser"),patch(f"{MODULE}.get_user_db_session", return_value=ctx),@@ -761,7 +804,9 @@ class TestGetSubscriptionsOrganized:):resp = client.get("/news/api/subscription/subscriptions/organized")assert resp.status_code == 200- assert "General" in resp.get_json()+ ids = {s["id"] for s in resp.get_json()["uncategorized"]}+ # Neither the folder's sub nor the ungrouped sub is dropped.+ assert ids == {"folder_sub", "ungrouped_sub"}SCHED_MOD = "local_deep_research.scheduler.background"diff --git a/tests/news/test_flask_api_deep_coverage.py b/tests/news/test_flask_api_deep_coverage.pyindex 98f4d62490..055039a366 100644--- a/tests/news/test_flask_api_deep_coverage.py+++ b/tests/news/test_flask_api_deep_coverage.py@@ -1383,9 +1383,12 @@ class TestGetSubscriptionsOrganized:"""Tests for the /subscription/subscriptions/organized endpoint."""def test_returns_organized(self, authed_client):+ # get_subscriptions_by_folder returns plain dicts in a+ # {"folders": [{"folder": {...}, "subscriptions": [...]}],+ # "uncategorized": [...]} shape; the route flattens to+ # {folder_name: [subscription, ...]}. (Calling .to_dict() on those+ # dicts previously 500'd the route.)patches = _auth_patches()- mock_sub = MagicMock()- mock_sub.to_dict.return_value = {"id": "s1", "query": "AI"}with (patches["db_manager"] as mock_db,@@ -1401,7 +1404,13 @@ class TestGetSubscriptionsOrganized:)mock_sess.return_value.__exit__ = MagicMock(return_value=False)MockFM.return_value.get_subscriptions_by_folder.return_value = {- "Work": [mock_sub],+ "folders": [+ {+ "folder": {"id": "f1", "name": "Work"},+ "subscriptions": [{"id": "s1", "query_or_topic": "AI"}],+ },+ ],+ "uncategorized": [],}resp = authed_client.get(@@ -1409,8 +1418,8 @@ class TestGetSubscriptionsOrganized:)assert resp.status_code == 200data = resp.get_json()- assert "Work" in data- assert len(data["Work"]) == 1+ assert data["Work"] == [{"id": "s1", "query_or_topic": "AI"}]+ assert data["uncategorized"] == []def test_exception_returns_500(self, authed_client):patches = _auth_patches()diff --git a/tests/news/test_news_api_extended.py b/tests/news/test_news_api_extended.pyindex 9a32ecf646..3396ccceeb 100644--- a/tests/news/test_news_api_extended.py+++ b/tests/news/test_news_api_extended.py@@ -893,6 +893,78 @@ class TestSubscriptionHistory:with pytest.raises(SubscriptionNotFoundException):get_subscription_history("nonexistent")+ def _run_history(self, sub, history_rows):+ """Drive get_subscription_history with a real NewsSubscription and a+ mocked research-history result. Both get_user_db_session() blocks share+ one mocked session."""+ from local_deep_research.news.api import get_subscription_history++ session = MagicMock()+ # First block: subscription lookup via filter_by(...).first()+ session.query.return_value.filter_by.return_value.first.return_value = (+ sub+ )+ # Second block: history via filter(...).order_by(...).limit(...).all()+ (+ session.query.return_value.filter.return_value.order_by.return_value.limit.return_value.all.return_value+ ) = history_rows++ with patch(+ "local_deep_research.database.session_context.get_user_db_session"+ ) as mock_get_session:+ mock_get_session.return_value.__enter__ = Mock(return_value=session)+ mock_get_session.return_value.__exit__ = Mock(return_value=False)+ return get_subscription_history("sub_1")++ def test_real_subscription_has_no_refresh_count_column(self):+ """Regression: NewsSubscription has no refresh_count column. Reading it+ raised AttributeError and 500'd the endpoint. With no runs, refresh_count+ is 0 and the call succeeds."""+ from local_deep_research.database.models.news import NewsSubscription++ sub = NewsSubscription(+ id="sub_1",+ query_or_topic="q",+ subscription_type="topic",+ refresh_interval_minutes=60,+ )++ result = self._run_history(sub, [])++ assert result["subscription"]["refresh_count"] == 0+ assert result["total_runs"] == 0++ def test_refresh_count_reflects_history_length(self):+ """refresh_count is derived from the research-run history."""+ from datetime import datetime, timezone++ from local_deep_research.database.models.news import NewsSubscription++ sub = NewsSubscription(+ id="sub_1",+ query_or_topic="q",+ subscription_type="topic",+ refresh_interval_minutes=60,+ )++ rows = []+ for i in range(3):+ row = MagicMock()+ row.id = f"r{i}"+ row.query = "q"+ row.status = "completed"+ row.created_at = datetime(2026, 6, 10, tzinfo=timezone.utc)+ row.completed_at = None+ row.duration_seconds = 1+ row.research_meta = None+ row.report_path = None+ rows.append(row)++ result = self._run_history(sub, rows)++ assert result["subscription"]["refresh_count"] == 3+ assert result["total_runs"] == 3+class TestVoteFunctions:"""Tests for vote/feedback functions."""