: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(data-imports): skip billing check instead of crashing when the job is missing (#88319)
Tom Owers1d3b90eb3091
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/check_billing_limits.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/check_billing_limits.pyindex b618e7609fa6..c379a1656d9b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/check_billing_limits.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/check_billing_limits.py@@ -45,7 +45,16 @@ def check_billing_limits_activity(inputs: CheckBillingLimitsActivityInputs) -> blogger = LOGGER.bind()close_old_connections()- job = ExternalDataJob.objects.get(id=inputs.job_id)+ try:+ job = ExternalDataJob.objects.get(id=inputs.job_id)+ except ExternalDataJob.DoesNotExist:+ # job_id can be None (or point at a job that no longer exists) when this input came+ # from an older worker's create_external_data_job_model_activity result — that legacy+ # compatibility path doesn't guarantee a job was created. Nothing to bill for, so let+ # the sync proceed rather than fail the whole workflow.+ logger.info("Skipping billing limits check: job does not exist", job_id=inputs.job_id)+ return False+source: ExternalDataSource = job.pipelineif not job.billable:diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_check_billing_limits.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_check_billing_limits.pynew file mode 100644index 000000000000..def4cac89a0b--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_check_billing_limits.py@@ -0,0 +1,32 @@+import uuid++import pytest++from posthog.models import Organization, Team++from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.check_billing_limits import (+ CheckBillingLimitsActivityInputs,+ check_billing_limits_activity,+)+++def _team() -> Team:+ return Team.objects.create(organization=Organization.objects.create(name="org"), name="t")+++# transaction=True: the activity calls close_old_connections(), which breaks the atomic wrapper+# a plain django_db test relies on for rollback (same reason test_calculate_table_size.py's+# activity-level test uses it).[email protected]_db(transaction=True)+class TestCheckBillingLimitsActivity:+ def test_skips_check_when_job_does_not_exist(self) -> None:+ # job_id can arrive as None (or point at a job that's gone) from a legacy+ # create_external_data_job_model_activity result — this used to raise+ # ExternalDataJob.DoesNotExist and crash the whole workflow instead of skipping the check.+ team = _team()++ result = check_billing_limits_activity(+ CheckBillingLimitsActivityInputs(team_id=team.id, job_id=str(uuid.uuid4()))+ )++ assert result is False