fix(sources): drop no-op try/except + url-encode S2 ids (audit R-4, R-5)
- R-4: arxiv.fetch_source had a try/except httpx.RequestError that only re-raised — removed (no behaviour change, less noise). - R-5: semanticscholar URLs now quote(paper_id, safe=':') so a legacy-arXiv '/' (arXiv:math/0603097) doesn't corrupt the path and silently return no references. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,10 +38,7 @@ def fetch_source(arxiv_id: str) -> str | None:
|
|||||||
file is present (signals Nougat fallback).
|
file is present (signals Nougat fallback).
|
||||||
"""
|
"""
|
||||||
url = f"{_BASE}/src/{arxiv_id}"
|
url = f"{_BASE}/src/{arxiv_id}"
|
||||||
try:
|
response = httpx.get(url, timeout=60, follow_redirects=True)
|
||||||
response = httpx.get(url, timeout=60, follow_redirects=True)
|
|
||||||
except httpx.RequestError:
|
|
||||||
raise
|
|
||||||
if response.status_code == 404:
|
if response.status_code == 404:
|
||||||
logger.debug("arXiv 404 for source id=%s", arxiv_id)
|
logger.debug("arXiv 404 for source id=%s", arxiv_id)
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from tenacity import retry, retry_if_exception, stop_after_attempt, wait_exponential
|
from tenacity import retry, retry_if_exception, stop_after_attempt, wait_exponential
|
||||||
@@ -77,7 +78,9 @@ def fetch_references(paper_id: str) -> list[Citation]:
|
|||||||
list[Citation]
|
list[Citation]
|
||||||
One Citation per reference, with optional context snippet.
|
One Citation per reference, with optional context snippet.
|
||||||
"""
|
"""
|
||||||
url = f"{_BASE_GRAPH}/paper/{paper_id}/references"
|
# quote the id so a legacy-arXiv "/" (e.g. arXiv:math/0603097) doesn't break
|
||||||
|
# the URL path; keep ":" for the arXiv:/DOI: scheme prefix (audit R-5).
|
||||||
|
url = f"{_BASE_GRAPH}/paper/{quote(paper_id, safe=':')}/references"
|
||||||
params: dict[str, Any] = {"fields": "externalIds,contexts"}
|
params: dict[str, Any] = {"fields": "externalIds,contexts"}
|
||||||
try:
|
try:
|
||||||
response = _get(url, params=params)
|
response = _get(url, params=params)
|
||||||
@@ -118,7 +121,7 @@ def fetch_recommendations(paper_id: str, limit: int = 20) -> list[str]:
|
|||||||
list[str]
|
list[str]
|
||||||
List of recommended paper IDs.
|
List of recommended paper IDs.
|
||||||
"""
|
"""
|
||||||
url = f"{_BASE_RECS}/papers/forpaper/{paper_id}"
|
url = f"{_BASE_RECS}/papers/forpaper/{quote(paper_id, safe=':')}"
|
||||||
params: dict[str, Any] = {"limit": limit}
|
params: dict[str, Any] = {"limit": limit}
|
||||||
try:
|
try:
|
||||||
response = _get(url, params=params)
|
response = _get(url, params=params)
|
||||||
|
|||||||
Reference in New Issue
Block a user