fix: preserve pagination candidate type narrowing

This commit is contained in:
lda
2026-09-09 22:07:50 +07:00 Verified
parent c799bdcb66
commit 595a1fe827
+5 -5
View File
@@ -476,9 +476,9 @@ class WorkflowScheduleApi:
raise ValueError("limit must be between 1 and 100") raise ValueError("limit must be between 1 and 100")
first_page = cursor in (None, "0") first_page = cursor in (None, "0")
candidate = store.get_candidate(schedule_id) candidate = store.get_candidate(schedule_id)
include_pending = candidate is not None and first_page pending_candidate = candidate if first_page else None
stored_cursor = None if cursor == _PENDING_PAGE_CURSOR else cursor stored_cursor = None if cursor == _PENDING_PAGE_CURSOR else cursor
stored_limit = limit - 1 if include_pending else limit stored_limit = limit - 1 if pending_candidate is not None else limit
if stored_limit: if stored_limit:
page = store.list_occurrences( page = store.list_occurrences(
schedule_id, schedule_id,
@@ -501,16 +501,16 @@ class WorkflowScheduleApi:
"next_cursor": (_PENDING_PAGE_CURSOR if stored_page["total"] else None), "next_cursor": (_PENDING_PAGE_CURSOR if stored_page["total"] else None),
"limit": limit, "limit": limit,
} }
if include_pending: if pending_candidate is not None:
now = datetime.now(UTC) now = datetime.now(UTC)
intended = candidate.intended_at intended = pending_candidate.intended_at
pending = OccurrenceRecord( pending = OccurrenceRecord(
schedule_id=schedule_id, schedule_id=schedule_id,
occurrence_id=occurrence_id(schedule_id, intended), occurrence_id=occurrence_id(schedule_id, intended),
kind="pending", kind="pending",
resolved_at=intended, resolved_at=intended,
run_id=None, run_id=None,
revision=candidate.revision, revision=pending_candidate.revision,
reason="", reason="",
admitted_at=None, admitted_at=None,
started_at=None, started_at=None,