From aaf76ac72c694c3f28c3b492e4aa6563096d1721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Fri, 20 Oct 2023 00:22:56 +0200 Subject: [PATCH] fix(backfill-batch-exports): Do not run partial ranges (#18114) --- .../batch_exports/test_backfill_batch_export.py | 15 +++++++++++++++ .../temporal/workflows/backfill_batch_export.py | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/posthog/temporal/tests/batch_exports/test_backfill_batch_export.py b/posthog/temporal/tests/batch_exports/test_backfill_batch_export.py index d91eec51651d0..6b4ffbe4de5f9 100644 --- a/posthog/temporal/tests/batch_exports/test_backfill_batch_export.py +++ b/posthog/temporal/tests/batch_exports/test_backfill_batch_export.py @@ -128,6 +128,21 @@ async def temporal_worker(temporal_client): ) ], ), + ( + dt.datetime(2023, 1, 1, 10, 0, 0, tzinfo=dt.timezone.utc), + dt.datetime(2023, 1, 1, 12, 20, 0, tzinfo=dt.timezone.utc), + dt.timedelta(hours=1), + [ + ( + dt.datetime(2023, 1, 1, 10, 0, 0, tzinfo=dt.timezone.utc), + dt.datetime(2023, 1, 1, 11, 0, 0, tzinfo=dt.timezone.utc), + ), + ( + dt.datetime(2023, 1, 1, 11, 0, 0, tzinfo=dt.timezone.utc), + dt.datetime(2023, 1, 1, 12, 0, 0, tzinfo=dt.timezone.utc), + ), + ], + ), ( dt.datetime(2023, 1, 1, 0, 0, 0, tzinfo=dt.timezone.utc), dt.datetime(2023, 1, 2, 0, 0, 0, tzinfo=dt.timezone.utc), diff --git a/posthog/temporal/workflows/backfill_batch_export.py b/posthog/temporal/workflows/backfill_batch_export.py index 10cc2d31d42ed..24b00c81876ab 100644 --- a/posthog/temporal/workflows/backfill_batch_export.py +++ b/posthog/temporal/workflows/backfill_batch_export.py @@ -244,7 +244,9 @@ def backfill_range( current_end = current + step if current_end > end_at: - current_end = end_at + # Do not yield a range that is less than step. + # Same as built-in range. + break yield current, current_end