:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(warehouse-sources): clear persona's resume cursor on completion (#103469)
jake sciotto584fdd04b4e2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/persona/persona.py b/products/warehouse_sources/backend/temporal/data_imports/sources/persona/persona.pyindex 07aef419da16..9b31031c2ac8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/persona/persona.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/persona/persona.py@@ -292,6 +292,11 @@ def get_rows(if batcher.should_yield(include_incomplete_chunk=True):yield batcher.get_table()+ # Walked to completion, so drop the checkpoint. Persona lists newest-first, so a cursor left+ # over from a finished walk points at the oldest object it saw: the next run would resume below+ # its whole created-at window instead of starting at page one.+ resumable_source_manager.clear_state()+def persona_source(api_key: str,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/persona/tests/test_persona.py b/products/warehouse_sources/backend/temporal/data_imports/sources/persona/tests/test_persona.pyindex caaa71ad963c..2d3eefd73ae7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/persona/tests/test_persona.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/persona/tests/test_persona.py@@ -28,6 +28,7 @@ class _FakeResumableManager:def __init__(self, state: PersonaResumeConfig | None = None) -> None:self._state = stateself.saved: list[PersonaResumeConfig] = []+ self.cleared = 0def can_resume(self) -> bool:return self._state is not None@@ -38,6 +39,9 @@ class _FakeResumableManager:def save_state(self, data: PersonaResumeConfig) -> None:self.saved.append(data)+ def clear_state(self) -> None:+ self.cleared += 1+class TestFormatDatetimeZ:@parameterized.expand(@@ -294,6 +298,51 @@ class TestResume:# First request on resume must carry the saved page[after] cursor.assert "page[after]=inq_saved" in manager.fetched_urls[0] # type: ignore[attr-defined]+ def test_clears_the_cursor_once_the_walk_completes(self, monkeypatch: Any) -> None:+ pages = [+ {+ "data": [{"type": "inquiry", "id": "inq_1", "attributes": {"created-at": "2026-01-03T00:00:00.000Z"}}],+ "links": {"next": None},+ }+ ]+ manager = _FakeResumableManager()+ _collect(manager, monkeypatch, pages)+ assert manager.cleared == 1++ def test_keeps_the_cursor_when_the_walk_does_not_finish(self, monkeypatch: Any) -> None:+ # A run cut short by a worker restart must leave its checkpoint behind, so the next attempt+ # resumes mid-window instead of re-walking from the last completed watermark.+ pages = iter(+ [+ {+ "data": [+ {"type": "inquiry", "id": "inq_1", "attributes": {"created-at": "2026-01-03T00:00:00.000Z"}}+ ],+ "links": {"next": "/api/v1/inquiries?page[after]=inq_1"},+ }+ ]+ )++ def fake_fetch(session: Any, url: str, headers: dict[str, str], logger: Any) -> dict:+ try:+ return next(pages)+ except StopIteration:+ raise PersonaRetryableError("worker went away")++ monkeypatch.setattr(persona, "_fetch_page", fake_fetch)++ manager = _FakeResumableManager()+ with pytest.raises(PersonaRetryableError):+ for _ in get_rows(+ api_key="persona_test",+ endpoint="inquiries",+ logger=MagicMock(),+ resumable_source_manager=manager, # type: ignore[arg-type]+ ):+ pass++ assert manager.cleared == 0+def _verifications(count: int, prefix: str) -> list[dict]:return [