Skip to content

: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.

fix(data-modeling): report real backfill status in dry-run (#68206)

Jovan Sakovic729ee8eaa642
diff --git a/products/data_modeling/backend/management/commands/backfill_dag_schedule_type.py b/products/data_modeling/backend/management/commands/backfill_dag_schedule_type.py
index 51267a540ea4..e1c26c7d9872 100644
--- a/products/data_modeling/backend/management/commands/backfill_dag_schedule_type.py
+++ b/products/data_modeling/backend/management/commands/backfill_dag_schedule_type.py
@@ -26,10 +26,21 @@ class Command(BaseCommand):
def handle(self, *args, **options):
dry_run = options["dry_run"]
- found, updated, failed = _backfill_schedule_type(dry_run)
+ found, already_stamped, updated, failed = _backfill_schedule_type(dry_run)
verb = "would stamp" if dry_run else "stamped"
- logger.info("Backfill complete", execute_dag_schedules=found, updated=updated, failed=failed, dry_run=dry_run)
- self.stdout.write(f"execute-dag schedules found: {found}; {verb}: {updated}; failed: {failed}")
+ stamped = found - already_stamped if dry_run else updated
+ logger.info(
+ "Backfill complete",
+ execute_dag_schedules=found,
+ already_stamped=already_stamped,
+ updated=updated,
+ failed=failed,
+ dry_run=dry_run,
+ )
+ self.stdout.write(
+ f"execute-dag schedules found: {found}; already stamped: {already_stamped}; "
+ f"{verb}: {stamped}; failed: {failed}"
+ )
async def _updater(input: ScheduleUpdateInput) -> ScheduleUpdate:
@@ -40,9 +51,10 @@ async def _updater(input: ScheduleUpdateInput) -> ScheduleUpdate:
@async_to_sync
-async def _backfill_schedule_type(dry_run: bool) -> tuple[int, int, int]:
+async def _backfill_schedule_type(dry_run: bool) -> tuple[int, int, int, int]:
temporal = await async_connect()
found = 0
+ already_stamped = 0
updated = 0
failed = 0
async for listing in await temporal.list_schedules():
@@ -53,6 +65,9 @@ async def _backfill_schedule_type(dry_run: bool) -> tuple[int, int, int]:
):
continue
found += 1
+ if listing.typed_search_attributes.get(POSTHOG_SCHEDULE_TYPE_KEY) == DATA_MODELING_EXECUTE_DAG_WORKFLOW:
+ already_stamped += 1
+ continue
if dry_run:
continue
try:
@@ -61,4 +76,4 @@ async def _backfill_schedule_type(dry_run: bool) -> tuple[int, int, int]:
except Exception:
failed += 1
logger.exception("Error stamping schedule", schedule_id=listing.id)
- return found, updated, failed
+ return found, already_stamped, updated, failed
diff --git a/products/data_modeling/backend/test/test_backfill_dag_schedule_type.py b/products/data_modeling/backend/test/test_backfill_dag_schedule_type.py
new file mode 100644
index 000000000000..2fb1702c751a
--- /dev/null
+++ b/products/data_modeling/backend/test/test_backfill_dag_schedule_type.py
@@ -0,0 +1,55 @@
+from unittest import mock
+
+from parameterized import parameterized
+from temporalio.client import ScheduleListActionStartWorkflow
+from temporalio.common import SearchAttributePair, TypedSearchAttributes
+
+from posthog.temporal.common.search_attributes import POSTHOG_SCHEDULE_TYPE_KEY
+
+from products.data_modeling.backend.management.commands.backfill_dag_schedule_type import _backfill_schedule_type
+from products.data_modeling.backend.schedule import DATA_MODELING_EXECUTE_DAG_WORKFLOW
+
+
+class TestBackfillScheduleType:
+ def _listing(self, schedule_id: str, workflow: str, schedule_type: str | None = None):
+ action = mock.Mock(spec=ScheduleListActionStartWorkflow, workflow=workflow)
+ attrs = TypedSearchAttributes(
+ [SearchAttributePair(POSTHOG_SCHEDULE_TYPE_KEY, schedule_type)] if schedule_type else []
+ )
+ return mock.Mock(id=schedule_id, schedule=mock.Mock(action=action), typed_search_attributes=attrs)
+
+ def _temporal(self, listings):
+ async def fake_list_schedules(*args, **kwargs):
+ async def gen():
+ for listing in listings:
+ yield listing
+
+ return gen()
+
+ temporal = mock.Mock()
+ temporal.list_schedules = fake_list_schedules
+ temporal.get_schedule_handle = mock.Mock(return_value=mock.Mock(update=mock.AsyncMock()))
+ return temporal
+
+ @parameterized.expand(
+ [
+ ("dry_run", True, 0, []),
+ ("real_run", False, 2, ["missing-1", "missing-2"]),
+ ]
+ )
+ def test_counts_stamped_vs_missing_and_updates_only_missing(self, _name, dry_run, expected_updated, updated_ids):
+ listings = [
+ self._listing("already-stamped", DATA_MODELING_EXECUTE_DAG_WORKFLOW, DATA_MODELING_EXECUTE_DAG_WORKFLOW),
+ self._listing("missing-1", DATA_MODELING_EXECUTE_DAG_WORKFLOW),
+ self._listing("missing-2", DATA_MODELING_EXECUTE_DAG_WORKFLOW),
+ self._listing("v1-schedule", "data-modeling-run"),
+ ]
+ temporal = self._temporal(listings)
+ with mock.patch(
+ "products.data_modeling.backend.management.commands.backfill_dag_schedule_type.async_connect",
+ new=mock.AsyncMock(return_value=temporal),
+ ):
+ found, already_stamped, updated, failed = _backfill_schedule_type(dry_run)
+
+ assert (found, already_stamped, updated, failed) == (3, 1, expected_updated, 0)
+ assert [call.args[0] for call in temporal.get_schedule_handle.call_args_list] == updated_ids