: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(growth): abort cloud label runs when the firecrawl key is missing (#109234)
Matt Brookerae8faae2389b
diff --git a/products/growth/backend/management/commands/enrichment_label_batch.py b/products/growth/backend/management/commands/enrichment_label_batch.pyindex c4d788956e5c..79a9256a7da8 100644--- a/products/growth/backend/management/commands/enrichment_label_batch.py+++ b/products/growth/backend/management/commands/enrichment_label_batch.py@@ -16,6 +16,7 @@ from datetime import datetimefrom typing import Anyfrom uuid import UUID+from django.conf import settingsfrom django.core.management.base import BaseCommand, CommandError, CommandParserfrom django.db import close_old_connections, connection, transactionfrom django.db.models import Q@@ -163,6 +164,11 @@ class Command(BaseCommand):validate_output_fields(config)except PromptConfigError as e:raise CommandError(str(e)) from e+ if gates.region_allowed() and not settings.FIRECRAWL_API_KEY:+ raise CommandError(+ "FIRECRAWL_API_KEY is not configured, so every org whose model turn calls a web tool would be "+ "deferred after a paid model call; aborting before any spend"+ )lock_key = _advisory_lock_key(label)with connection.cursor() as cursor:diff --git a/products/growth/backend/tests/test_ai_pilled.py b/products/growth/backend/tests/test_ai_pilled.pyindex db48c434de37..62510613d542 100644--- a/products/growth/backend/tests/test_ai_pilled.py+++ b/products/growth/backend/tests/test_ai_pilled.py@@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, MagicMock, patchfrom django.core.management import call_commandfrom django.core.management.base import CommandError+from django.test import override_settingsfrom asgiref.sync import async_to_syncfrom parameterized import parameterized@@ -36,6 +37,7 @@ from products.growth.backend.models import (_BACKFILL = "products.growth.backend.management.commands.backfill_icp_fit_scores"+@override_settings(FIRECRAWL_API_KEY="fc-test-key")class TestEnrichmentScoreApplication(BaseTest):def setUp(self):super().setUp()diff --git a/products/growth/backend/tests/test_enrichment_label_commands.py b/products/growth/backend/tests/test_enrichment_label_commands.pyindex f47de0932228..28db1bb102c3 100644--- a/products/growth/backend/tests/test_enrichment_label_commands.py+++ b/products/growth/backend/tests/test_enrichment_label_commands.py@@ -10,6 +10,7 @@ from unittest.mock import MagicMock, patchfrom django.core.management import call_commandfrom django.core.management.base import CommandErrorfrom django.db import connection+from django.test import override_settingsfrom django.utils import timezonefrom parameterized import parameterized@@ -424,6 +425,32 @@ class TestExpectedVersionGuard(_BatchCommandTestCase):assert EnrichmentLabelResult.objects.count() == 1+class TestFirecrawlKeyGuard(_BatchCommandTestCase):+ @parameterized.expand(+ [+ ("cloud_missing_key", "EU", "", True),+ ("cloud_with_key", "EU", "fc-test-key", False),+ ("e2e_dev_missing_key", "E2E", "", False),+ ]+ )+ def test_a_cloud_run_needs_the_firecrawl_key_before_any_spend(self, _name, cloud_deployment, firecrawl_key, aborts):+ self._config()+ self._fetch()+ client = _mock_llm_client()++ with (+ override_settings(CLOUD_DEPLOYMENT=cloud_deployment, FIRECRAWL_API_KEY=firecrawl_key),+ patch(f"{_BATCH_COMMAND_MODULE}.get_llm_client", return_value=client),+ ):+ if aborts:+ with self.assertRaisesMessage(CommandError, "FIRECRAWL_API_KEY"):+ call_command("enrichment_label_batch", label="test_label", workers=1)+ else:+ call_command("enrichment_label_batch", label="test_label", workers=1)++ assert client.chat.completions.create.called is not aborts++class TestWorkerConnectionErrors(NonAtomicBaseTest):"""Non-atomic: worker threads get their own DB connections, matching the pattern inTestEnrichmentLabelBatchConcurrency (test_enrichment_labels.py) for the same reason."""