~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): honor flat source_type fields in SQLCardStorage.create() (#4245)
LearningCircuitc433c876e9d1
diff --git a/src/local_deep_research/news/core/card_storage.py b/src/local_deep_research/news/core/card_storage.pyindex 996e439435..07dd6cc22e 100644--- a/src/local_deep_research/news/core/card_storage.py+++ b/src/local_deep_research/news/core/card_storage.py@@ -48,9 +48,13 @@ class SQLCardStorage(CardStorage):"""card_id = data.get("id") or self.generate_id()- # Extract source info if it's nested- source_info = data.get("source", {})- if isinstance(source_info, dict):+ # Extract source info if it's nested under "source"; otherwise+ # fall back to the flat source_type / source_id / created_from+ # fields. Note: `data.get("source", {})` returns {} when missing,+ # which is itself a dict — so check truthiness, not type, to+ # decide which branch applies.+ source_info = data.get("source")+ if isinstance(source_info, dict) and source_info:source_type = source_info.get("type")source_id = source_info.get("source_id")created_from = source_info.get("created_from")diff --git a/tests/news/core/test_card_storage.py b/tests/news/core/test_card_storage.pyindex 4653a89f27..501f6b6b8b 100644--- a/tests/news/core/test_card_storage.py+++ b/tests/news/core/test_card_storage.py@@ -12,9 +12,11 @@ Tests cover:- archive_card() and pin_card()"""-import pytest+import uuidfrom unittest.mock import MagicMock, patch+import pytest+class TestSQLCardStorageInit:"""Tests for SQLCardStorage initialization."""@@ -65,8 +67,8 @@ class TestSQLCardStorageCreate:"""Tests for SQLCardStorage.create() method."""def test_create_with_nested_source_info(self):- """Test card creation with nested source info."""- # audit: PUNCHLIST reviewed 2026-05 — issue resolved by prior PR (recommendation: REWRITE_WITH_REAL_SESSION_OR_DELETE).+ """Nested source dict must be unpacked into source_type / source_id;+ created_from goes into extra_data; topic maps to title."""from local_deep_research.news.core.card_storage import SQLCardStoragemock_session = MagicMock()@@ -91,18 +93,33 @@ class TestSQLCardStorageCreate:with patch("local_deep_research.news.core.card_storage.NewsCard") as MockNewsCard:- mock_card = MagicMock()- MockNewsCard.return_value = mock_card+ MockNewsCard.return_value = MagicMock()result = storage.create(data)assert result == "card-123"- mock_context.add.assert_called_once_with(mock_card)mock_context.commit.assert_called_once()+ # Verify the SUT mapped fields correctly into the NewsCard ctor.+ kwargs = MockNewsCard.call_args.kwargs+ assert kwargs["id"] == "card-123"+ assert kwargs["title"] == "Test Topic", "topic must map to title"+ assert kwargs["card_type"] == "news"+ assert kwargs["source_type"] == "news_search", (+ "nested source.type must map to source_type"+ )+ assert kwargs["source_id"] == "search-789", (+ "nested source.source_id must map to source_id"+ )+ assert kwargs["extra_data"]["user_id"] == "user-456"+ assert kwargs["extra_data"]["created_from"] == "Analysis", (+ "nested source.created_from must land in extra_data"+ )+def test_create_with_flat_source_info(self):- """Test card creation with flat source info."""- # audit: PUNCHLIST reviewed 2026-05 — issue resolved by prior PR (recommendation: REWRITE_WITH_REAL_SESSION).+ """Flat source_type / source_id / created_from must be honored when+ there is no nested 'source' dict; missing id must be auto-generated+ as a UUID."""from local_deep_research.news.core.card_storage import SQLCardStoragemock_session = MagicMock()@@ -123,17 +140,30 @@ class TestSQLCardStorageCreate:with patch("local_deep_research.news.core.card_storage.NewsCard") as MockNewsCard:- mock_card = MagicMock()- MockNewsCard.return_value = mock_card+ MockNewsCard.return_value = MagicMock()result = storage.create(data)- # Should generate an ID since none was providedassert isinstance(result, str)- assert len(result) == 36 # UUID format- mock_context.add.assert_called_once()+ assert len(result) == 36, "auto-generated id must be a UUID"+ uuid.UUID(result) # must be parseable as UUIDmock_context.commit.assert_called_once()+ kwargs = MockNewsCard.call_args.kwargs+ assert kwargs["id"] == result, (+ "auto-generated id must be passed to NewsCard"+ )+ assert kwargs["title"] == "Test Topic"+ assert kwargs["source_type"] == "manual", (+ "flat source_type must be honored"+ )+ assert kwargs["source_id"] == "src-123", (+ "flat source_id must be honored"+ )+ assert kwargs["extra_data"]["created_from"] == "User input", (+ "flat created_from must land in extra_data"+ )+def test_create_uses_type_fallback_for_card_type(self):"""Test that 'type' field is used as fallback for card_type."""from local_deep_research.news.core.card_storage import SQLCardStorage