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.

fix: handle None input in metrics domain extraction (#3025)

perrya1266c9e6556
diff --git a/src/local_deep_research/web/routes/metrics_routes.py b/src/local_deep_research/web/routes/metrics_routes.py
index c07500ddeb..9a8cdabe4e 100644
--- a/src/local_deep_research/web/routes/metrics_routes.py
+++ b/src/local_deep_research/web/routes/metrics_routes.py
@@ -44,7 +44,7 @@ def _extract_domain(url):
if domain.startswith("www."):
domain = domain[4:]
return domain if domain else None
- except (ValueError, AttributeError):
+ except (ValueError, AttributeError, TypeError):
return None
diff --git a/tests/web/routes/test_extract_domain.py b/tests/web/routes/test_extract_domain.py
index a4716696d6..9d46c73395 100644
--- a/tests/web/routes/test_extract_domain.py
+++ b/tests/web/routes/test_extract_domain.py
@@ -28,12 +28,9 @@ class TestExtractDomain:
def test_empty_string_returns_none(self):
assert _extract_domain("") is None
- def test_none_input_raises(self):
- """urlparse(None) produces bytes netloc; TypeError not caught."""
- import pytest
-
- with pytest.raises(TypeError):
- _extract_domain(None)
+ def test_none_input_returns_none(self):
+ """None input should be handled defensively like other invalid URLs."""
+ assert _extract_domain(None) is None
def test_path_only_no_netloc_returns_none(self):
assert _extract_domain("/just/a/path") is None
diff --git a/tests/web/routes/test_metrics_analytics_logic.py b/tests/web/routes/test_metrics_analytics_logic.py
index cae432436f..25c203de12 100644
--- a/tests/web/routes/test_metrics_analytics_logic.py
+++ b/tests/web/routes/test_metrics_analytics_logic.py
@@ -5,8 +5,6 @@ These test the aggregation logic directly (mocking DB), not through HTTP endpoin
from unittest.mock import MagicMock, Mock, patch
-import pytest
-
from local_deep_research.database.models import (
ResearchHistory,
ResearchResource,
@@ -43,14 +41,9 @@ class TestExtractDomain:
== "example.com:8080"
)
- def test_none_raises_type_error(self):
- """urlparse(None) returns bytes-based ParseResult; .startswith(str) raises TypeError.
-
- This is an uncaught edge case — the except clause only catches
- ValueError and AttributeError, not TypeError.
- """
- with pytest.raises(TypeError):
- _extract_domain(None)
+ def test_none_returns_none(self):
+ """None input should be treated like other invalid URLs."""
+ assert _extract_domain(None) is None
def test_empty_string_returns_none(self):
assert _extract_domain("") is None
diff --git a/tests/web/routes/test_metrics_routes_coverage.py b/tests/web/routes/test_metrics_routes_coverage.py
index 42001b13ba..44fbc9f988 100644
--- a/tests/web/routes/test_metrics_routes_coverage.py
+++ b/tests/web/routes/test_metrics_routes_coverage.py
@@ -207,10 +207,9 @@ class TestExtractDomain:
def test_invalid_url_no_netloc(self):
assert _extract_domain("not-a-url") is None
- def test_none_input_raises(self):
- """None input causes TypeError which is NOT caught by the except clause."""
- with pytest.raises(TypeError):
- _extract_domain(None)
+ def test_none_input_returns_none(self):
+ """None input should return None instead of leaking TypeError."""
+ assert _extract_domain(None) is None
def test_url_with_port(self):
assert (