Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(merchant): keep polling while a task is handed or queued

Angelo2f38cbbd76f8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 648be42..8026e5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+
+- **Merchant (Google Shopping, Amazon) searches no longer crash while a task
+ is queued.** `dataforseo_merchant.py` kept polling only on 40601 ("Task
+ Handed"), so a 40602 ("Task In Queue") answer came back as a finished task
+ and `_extract_items` failed on its `result: null`. It now waits on both codes
+ and treats a null `result` as no items.
+
## [2.5.0] - 2026-10-22
Security and accuracy fixes from a full audit, and Claude Desktop installs again.
diff --git a/scripts/dataforseo_merchant.py b/scripts/dataforseo_merchant.py
index 2783add..f4e0ca9 100755
--- a/scripts/dataforseo_merchant.py
+++ b/scripts/dataforseo_merchant.py
@@ -157,8 +157,8 @@ def _poll_results(
return data
# Task not ready yet
task_status = tasks[0].get("status_code") if tasks else None
- if task_status and task_status != 40601:
- # 40601 = "Task In Queue" -- keep polling
+ if task_status and task_status not in (40601, 40602):
+ # 40601 = "Task Handed", 40602 = "Task In Queue" -- keep polling
# Other errors: return the error
return data
@@ -182,7 +182,7 @@ def _extract_items(response: dict[str, Any]) -> list[dict[str, Any]]:
"""Extract result items from DataForSEO response envelope."""
items = []
for task in response.get("tasks", []):
- for result in task.get("result", []):
+ for result in task.get("result") or []:
task_items = result.get("items")
if task_items:
items.extend(task_items)
diff --git a/tests/test_dataforseo_merchant_polling.py b/tests/test_dataforseo_merchant_polling.py
new file mode 100644
index 0000000..8e17049
--- /dev/null
+++ b/tests/test_dataforseo_merchant_polling.py
@@ -0,0 +1,72 @@
+"""DataForSEO Merchant task polling regressions.
+
+A Merchant task_get answers 40601 ("Task Handed") and then 40602 ("Task In
+Queue") while the task waits to run, both with ``result: null``. Codes from
+https://docs.dataforseo.com/v3/appendix/errors (verified 2026-10-27). The
+poller used to keep waiting on 40601 only, so a queued task came back as if it
+had finished and ``_extract_items`` crashed iterating ``None``.
+"""
+
+from __future__ import annotations
+
+import os
+import sys
+from unittest.mock import patch
+
+import pytest
+
+_SCRIPTS = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "scripts")
+if _SCRIPTS not in sys.path:
+ sys.path.insert(0, _SCRIPTS)
+
+pytest.importorskip("requests")
+import dataforseo_merchant # noqa: E402
+
+ITEM = {"type": "google_shopping_serp", "title": "Standing desk", "price": 249.0}
+
+
+def _task_get(task_status: int, result: list | None) -> dict:
+ return {
+ "status_code": 20000,
+ "tasks": [{"id": "task-1", "status_code": task_status, "result": result}],
+ }
+
+
+class FakeResponse:
+ def __init__(self, body: dict):
+ self._body = body
+
+ def raise_for_status(self) -> None:
+ return None
+
+ def json(self) -> dict:
+ return self._body
+
+
+def _poll(bodies: list[dict]) -> tuple[dict, int]:
+ responses = iter(FakeResponse(b) for b in bodies)
+ with patch.object(dataforseo_merchant.time, "sleep"), patch.object(
+ dataforseo_merchant.requests, "get", side_effect=lambda *a, **k: next(responses)
+ ) as get:
+ data = dataforseo_merchant._poll_results("google_products", "task-1", {})
+ return data, get.call_count
+
+
+def test_keeps_polling_while_task_is_handed_or_queued():
+ data, calls = _poll([
+ _task_get(40601, None),
+ _task_get(40602, None),
+ _task_get(20000, [{"items": [ITEM]}]),
+ ])
+ assert calls == 3
+ assert dataforseo_merchant._extract_items(data) == [ITEM]
+
+
+def test_returns_a_real_task_error_without_waiting():
+ data, calls = _poll([_task_get(40102, None)])
+ assert calls == 1
+ assert data["tasks"][0]["status_code"] == 40102
+
+
+def test_extract_items_tolerates_null_result():
+ assert dataforseo_merchant._extract_items(_task_get(40102, None)) == []