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: Return completed when batch export on demand has no data (#61392)

Tomás Farías Santanaf14300e9942d
diff --git a/products/batch_exports/backend/api/file_download.py b/products/batch_exports/backend/api/file_download.py
index f01b73ade849..5cf7255dad5b 100644
--- a/products/batch_exports/backend/api/file_download.py
+++ b/products/batch_exports/backend/api/file_download.py
@@ -358,7 +358,8 @@ class FileDownloadBatchExportOnDemandViewSet(
.values_list("id", flat=True)
]
- if not ids:
+ has_data = batch_export_run.records_completed is not None and batch_export_run.records_completed > 0
+ if not ids and has_data:
# There is currently a small delay between the run being set to completed
# and the file downloads being generated, so we account for that and keep
# showing running status.
diff --git a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.py b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.py
index 3fcc6447c2f8..4561105d78e7 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.py
@@ -215,6 +215,38 @@ async def test_file_download_retrieve_returns_files(
assert data["files"] == [str(file_download.id) for file_download in file_downloads]
[email protected]_db(transaction=True)
+async def test_file_download_retrieve_returns_empty_when_no_data_exported(
+ async_client: AsyncClient,
+ temporal_client,
+ team,
+ user,
+ data_interval_start,
+ data_interval_end,
+):
+ destination = await BatchExportDestination.objects.acreate(
+ type=BatchExportDestination.Destination.FILE_DOWNLOAD, config={}
+ )
+ with team_scope(team_id=team.pk, canonical=True):
+ batch_export = await BatchExportOnDemand.objects.acreate(team=team, destination=destination, model="events")
+ run = await BatchExportRun.objects.acreate(
+ batch_export_on_demand=batch_export,
+ data_interval_start=data_interval_start,
+ data_interval_end=data_interval_end,
+ status=BatchExportRun.Status.COMPLETED,
+ records_completed=0,
+ )
+
+ await async_client.aforce_login(user)
+
+ status_response = await async_client.get(
+ f"/api/projects/{team.pk}/file_download_batch_exports/{run.id}",
+ )
+ data = status_response.json()
+ assert data["status"] == "Completed", status_response.json()
+ assert data["files"] == []
+
+
@pytest.mark.usefixtures("override_file_download_settings")
@pytest.mark.django_db(transaction=True)
async def test_file_download_download_fails_when_not_completed(