Fail the read when Lever answers something other than a list or Oracle an answer without its search wrapper, instead of reading an empty board that is complete
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
19fb73caa0
commit
85aed0807b
4 files changed
+67
-5
No files matched your search
@@ -110,20 +110,31 @@ def page(get: Get, slug: str, cursor: Any, ask: Ask = Ask()) -> Page:
|
||||
`items[0]`. Without the `expand` only the facets come back; asking for
|
||||
`requisitionList.secondaryLocations` gives the roles and each one's other
|
||||
locations, which the plain `requisitionList` leaves out. Past the last role
|
||||
the list is empty."""
|
||||
the list is empty; an answer without the wrapper raises (`_search`)."""
|
||||
offset = int(cursor or 0)
|
||||
site = _parts(slug)[1]
|
||||
data = json.loads(get(
|
||||
f"{_api(slug)}/recruitingCEJobRequisitions?onlyData=true"
|
||||
f"&expand=requisitionList.secondaryLocations"
|
||||
f"&finder=findReqs;siteNumber={site},{_selected(ask)}limit={PAGE_SIZE},offset={offset}"))
|
||||
search = (data.get("items") or [{}])[0]
|
||||
search = _search(data)
|
||||
roles = search.get("requisitionList") or []
|
||||
# `_paged` counts `id`, which Oracle spells `Id`.
|
||||
results = [{"id": str(role.get("Id") or "")} for role in roles]
|
||||
return search, results, search.get("TotalJobsCount"), offset + len(roles) if roles else None
|
||||
|
||||
|
||||
def _search(data: Any) -> dict[str, Any]:
|
||||
"""The search wrapper of a listing's answer, `items[0]`. Every answer has
|
||||
one, past the last role too; one without (an error document sent with a
|
||||
200) raises, so the read fails and closes nothing rather than reading as
|
||||
an empty last page with no total, which is a complete read."""
|
||||
items = data.get("items") if isinstance(data, dict) else None
|
||||
if not isinstance(items, list) or not items or not isinstance(items[0], dict):
|
||||
raise ValueError("Oracle's answer has no search wrapper in items")
|
||||
return items[0]
|
||||
|
||||
|
||||
#: How many countries `locationsFacet` lists at most; a list this long may
|
||||
#: leave some out.
|
||||
FACET_LIMIT = 10
|
||||
@@ -162,7 +173,7 @@ def facets(get: Get, slug: str) -> dict[str, dict[str, str]]:
|
||||
|
||||
|
||||
def parse(body: bytes, slug: str) -> list[Row]:
|
||||
return rows((json.loads(body).get("items") or [{}])[0], slug)
|
||||
return rows(_search(json.loads(body)), slug)
|
||||
|
||||
|
||||
def _text(value: Any) -> str:
|
||||
|
||||
Reference in new issue
Block a user