fix(notion-search): make API errors non-fatal in search_candidates
Code review caught that without exception handling around
notion.search() and notion.data_sources.query(), any transient API
hiccup (rate limit, 5xx, network blip) would crash the whole search
and lose candidates already accumulated from earlier variants/DBs.
Wrap both calls in try/except, mirror the resolver's pattern: stderr
warning + continue. Same query against another variant or another DB
still has a chance to succeed.
Also tightened response.get("results", []) → response.get("results")
or [] so a hypothetical {"results": null} response doesn't crash the
inner loop.
17/17 tests still pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -114,8 +114,13 @@ def search_candidates(
|
|||||||
if prop_filter:
|
if prop_filter:
|
||||||
params["filter"] = prop_filter
|
params["filter"] = prop_filter
|
||||||
|
|
||||||
response = notion.data_sources.query(**params)
|
try:
|
||||||
for page in response.get("results", []):
|
response = notion.data_sources.query(**params)
|
||||||
|
except Exception as exc:
|
||||||
|
print(f"Warning: query failed for database {db_id}: {exc}",
|
||||||
|
file=sys.stderr)
|
||||||
|
continue
|
||||||
|
for page in response.get("results") or []:
|
||||||
page_id = page.get("id")
|
page_id = page.get("id")
|
||||||
if page_id and page_id not in seen_ids:
|
if page_id and page_id not in seen_ids:
|
||||||
seen_ids.add(page_id)
|
seen_ids.add(page_id)
|
||||||
@@ -124,8 +129,13 @@ def search_candidates(
|
|||||||
return candidates
|
return candidates
|
||||||
else:
|
else:
|
||||||
# Workspace-wide search
|
# Workspace-wide search
|
||||||
response = notion.search(query=query, page_size=100)
|
try:
|
||||||
for item in response.get("results", []):
|
response = notion.search(query=query, page_size=100)
|
||||||
|
except Exception as exc:
|
||||||
|
print(f"Warning: workspace search failed for variant {query!r}: {exc}",
|
||||||
|
file=sys.stderr)
|
||||||
|
continue
|
||||||
|
for item in response.get("results") or []:
|
||||||
if item.get("object") != "page":
|
if item.get("object") != "page":
|
||||||
continue
|
continue
|
||||||
page_id = item.get("id")
|
page_id = item.get("id")
|
||||||
|
|||||||
Reference in New Issue
Block a user