: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
chore(devex): stop core tests from running batch exports workflows (#127235)
Julian Bez2f9855439de4
diff --git a/posthog/api/test/test_team_deletion.py b/posthog/api/test/test_team_deletion.pyindex 8eee82b04023..3638dd70bfdd 100644--- a/posthog/api/test/test_team_deletion.py+++ b/posthog/api/test/test_team_deletion.py@@ -5,8 +5,6 @@ import time_machinefrom posthog.test.base import NonAtomicBaseTestfrom unittest.mock import ANY, patch-from django.conf import settings-from temporalio.service import RPCErrorfrom posthog.models import OrganizationMembership, Team@@ -14,10 +12,8 @@ from posthog.models.activity_logging.activity_log import ActivityLogfrom posthog.models.integration import Integrationfrom posthog.temporal.common.client import sync_connectfrom posthog.temporal.common.schedule import describe_schedule-from posthog.temporal.common.test_utils import start_test_workerfrom posthog.temporal.tests.delete_teams.inline import execute_deletion_workflows_inline-from products.batch_exports.backend.facade.temporal import ACTIVITIES, WORKFLOWSfrom products.early_access_features.backend.models import EarlyAccessFeaturefrom products.growth.backend.models import SdkVersionsDailyfrom products.web_analytics.backend.models.health_rollups import EventsHealthDaily, HostProxyDaily, SessionIdState@@ -233,29 +229,23 @@ class TestTeamDeletionSideEffects(NonAtomicBaseTest):temporal = sync_connect()- with start_test_worker(- temporal,- task_queue=settings.BATCH_EXPORTS_TASK_QUEUE,- workflows=WORKFLOWS,- activities=ACTIVITIES,- ):- response = self.client.post(- f"/api/environments/{team.id}/batch_exports",- json.dumps(batch_export_data),- content_type="application/json",- )- assert response.status_code == 201, response.json()- batch_export_id = response.json()["id"]+ response = self.client.post(+ f"/api/environments/{team.id}/batch_exports",+ json.dumps(batch_export_data),+ content_type="application/json",+ )+ assert response.status_code == 201, response.json()+ batch_export_id = response.json()["id"]- with execute_deletion_workflows_inline():- response = self.client.delete(f"/api/environments/{team.id}")- assert response.status_code == 204, response.json()+ with execute_deletion_workflows_inline():+ response = self.client.delete(f"/api/environments/{team.id}")+ assert response.status_code == 204, response.json()- response = self.client.get(f"/api/environments/{team.id}/batch_exports/{batch_export_id}")- assert response.status_code == 404, response.json()+ response = self.client.get(f"/api/environments/{team.id}/batch_exports/{batch_export_id}")+ assert response.status_code == 404, response.json()- with self.assertRaises(RPCError):- describe_schedule(temporal, batch_export_id)+ with self.assertRaises(RPCError):+ describe_schedule(temporal, batch_export_id)def test_delete_team_with_already_deleted_batch_export(self):"""Team deletion should succeed even if batch exports were already soft-deleted."""@@ -278,31 +268,25 @@ class TestTeamDeletionSideEffects(NonAtomicBaseTest):temporal = sync_connect()- with start_test_worker(- temporal,- task_queue=settings.BATCH_EXPORTS_TASK_QUEUE,- workflows=WORKFLOWS,- activities=ACTIVITIES,- ):- response = self.client.post(- f"/api/environments/{team.id}/batch_exports",- json.dumps(batch_export_data),- content_type="application/json",- )- assert response.status_code == 201, response.json()- batch_export_id = response.json()["id"]+ response = self.client.post(+ f"/api/environments/{team.id}/batch_exports",+ json.dumps(batch_export_data),+ content_type="application/json",+ )+ assert response.status_code == 201, response.json()+ batch_export_id = response.json()["id"]- # Delete the batch export first (this soft-deletes it and removes the Temporal schedule)- response = self.client.delete(f"/api/environments/{team.id}/batch_exports/{batch_export_id}")- assert response.status_code == 204+ # Delete the batch export first (this soft-deletes it and removes the Temporal schedule)+ response = self.client.delete(f"/api/environments/{team.id}/batch_exports/{batch_export_id}")+ assert response.status_code == 204- with self.assertRaises(RPCError):- describe_schedule(temporal, batch_export_id)+ with self.assertRaises(RPCError):+ describe_schedule(temporal, batch_export_id)- # Now delete the team - this should succeed- with execute_deletion_workflows_inline():- response = self.client.delete(f"/api/environments/{team.id}")- assert response.status_code == 204+ # Now delete the team - this should succeed+ with execute_deletion_workflows_inline():+ response = self.client.delete(f"/api/environments/{team.id}")+ assert response.status_code == 204@patch("posthog.temporal.common.client.sync_connect")@patch("products.data_modeling.backend.facade.api.delete_team_data_modeling_schedules")diff --git a/posthog/temporal/tests/conftest.py b/posthog/temporal/tests/conftest.pyindex 006261ecd79c..b041b10c60d1 100644--- a/posthog/temporal/tests/conftest.py+++ b/posthog/temporal/tests/conftest.py@@ -1,6 +1,5 @@import randomimport signal-import asynciofrom collections.abc import AsyncIteratorimport pytest@@ -9,7 +8,6 @@ from django.conf import settingsimport psycopgimport pytest_asyncio-import temporalio.workerfrom asgiref.sync import sync_to_asyncfrom psycopg import sqlfrom temporalio.testing import ActivityEnvironment@@ -129,54 +127,6 @@ async def temporal_client():yield client-@pytest_asyncio.fixture()-async def workflows(request):- """Return Temporal workflows to initialize a test worker.-- By default (no parametrization), we return all available workflows. Optionally,- with @pytest.mark.parametrize it is possible to customize which workflows the worker starts with.- """- try:- return request.param- except AttributeError:- from products.batch_exports.backend.facade.temporal import WORKFLOWS-- return WORKFLOWS---@pytest_asyncio.fixture()-async def activities(request):- """Return Temporal activities to initialize a test worker.-- By default (no parametrization), we return all available activities. Optionally,- with @pytest.mark.parametrize it is possible to customize which activities the worker starts with.- """- try:- return request.param- except AttributeError:- from products.batch_exports.backend.facade.temporal import ACTIVITIES-- return ACTIVITIES---@pytest_asyncio.fixture-async def temporal_worker(temporal_client, workflows, activities):- worker = temporalio.worker.Worker(- temporal_client,- task_queue=settings.TEMPORAL_TASK_QUEUE,- workflows=workflows,- activities=activities,- workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),- )-- worker_run = asyncio.create_task(worker.run())-- yield worker-- worker_run.cancel()- await asyncio.wait([worker_run])--@pytest_asyncio.fixture(autouse=True, scope="module", loop_scope="module")async def configure_logger_auto() -> AsyncIterator[None]:"""Configure logger for running temporal tests."""diff --git a/posthog/temporal/tests/test_encryption_codec.py b/posthog/temporal/tests/test_encryption_codec.pyindex 0f0e49ea3aa6..1ca48b985265 100644--- a/posthog/temporal/tests/test_encryption_codec.py+++ b/posthog/temporal/tests/test_encryption_codec.py@@ -1,6 +1,7 @@import jsonimport uuidimport base64+import datetime as dtimport dataclassesimport collections.abc@@ -10,14 +11,40 @@ from django.conf import settingsimport temporalio.converterfrom cryptography.fernet import InvalidToken+from temporalio import activity, workflowfrom temporalio.api.enums.v1 import EventTypefrom temporalio.client import Clientfrom temporalio.worker import UnsandboxedWorkflowRunner, Worker+from posthog.dataclasses import frozenfrom posthog.temporal.common.codec import EncryptionCodec, _load_as_bytes, _prepare_key, _resize_key-from products.batch_exports.backend.facade.temporal import NoOpWorkflow, noop_activity-from products.batch_exports.backend.facade.testing import build_noop_inputs++@frozen+class EchoWorkflowInputs:+ arg: str+ team_id: int+++@frozen+class EchoActivityInputs:+ arg: str++[email protected](name="encryption-codec-test-echo")+async def echo_activity(inputs: EchoActivityInputs) -> str:+ return f"OK - {inputs.arg}"++[email protected](name="encryption-codec-test-echo")+class EchoWorkflow:+ @workflow.run+ async def run(self, inputs: EchoWorkflowInputs) -> str:+ return await workflow.execute_activity(+ echo_activity,+ EchoActivityInputs(arg=inputs.arg),+ start_to_close_timeout=dt.timedelta(seconds=60),+ )@pytest.mark.parametrize(@@ -190,34 +217,33 @@ async def test_payloads_are_encrypted():workflow_id = uuid.uuid4()input_str = str(uuid.uuid4())- no_op_result_str = f"OK - {input_str}"- inputs = build_noop_inputs(arg=input_str, team_id=1, batch_export_id="123")+ echo_result_str = f"OK - {input_str}"+ inputs = EchoWorkflowInputs(arg=input_str, team_id=1)- # The no-op Workflow can only produce a limited set of results, so we'll check if the events match any of these.- # Either it's the final result (no_op_result_str), the input to an activity (no_op_activity_input_str), or the- # input to the workflow (inputs).+ # The echo Workflow can only produce a limited set of results, so we'll check if the events match any of these.+ # Either it's the final result (echo_result_str), the input to the activity, or the input to the workflow (inputs).expected_results = (- no_op_result_str,- {"arg": input_str, "backfill_details": None},+ echo_result_str,+ {"arg": input_str},dataclasses.asdict(inputs),)async with Worker(client,task_queue=settings.TEMPORAL_TASK_QUEUE,- workflows=[NoOpWorkflow],- activities=[noop_activity],+ workflows=[EchoWorkflow],+ activities=[echo_activity],workflow_runner=UnsandboxedWorkflowRunner(),) as worker:handle = await client.start_workflow(- NoOpWorkflow.run,+ EchoWorkflow.run,inputs,id=f"workflow-{workflow_id}",task_queue=worker.task_queue,)result = await handle.result()- assert result == no_op_result_str+ assert result == echo_result_strasync for event in handle.fetch_history_events():payloads = get_history_event_payloads(event)diff --git a/products/batch_exports/backend/facade/temporal.py b/products/batch_exports/backend/facade/temporal.pyindex 6250a28343a8..d45d174f822b 100644--- a/products/batch_exports/backend/facade/temporal.py+++ b/products/batch_exports/backend/facade/temporal.py@@ -3,9 +3,8 @@ Temporal registration wiring for batch_exports.Re-exports what core registers with Temporal: the worker bootstrap commands(``start_temporal_worker``, ``start_temporal_workflow``, ``execute_temporal_workflow``)-take ``WORKFLOWS`` and ``ACTIVITIES``, ``posthog/temporal/common/worker.py`` takes the-metrics interceptor, and the shared Temporal test conftest and payload-codec test take-the no-op workflow and its activity.+take ``WORKFLOWS`` and ``ACTIVITIES``, and ``posthog/temporal/common/worker.py`` takes the+metrics interceptor.Names resolve lazily (PEP 562), mirroring ``backend/temporal/__init__.py``. Eager importshere would put every destination's vendor SDK (databricks, snowflake, bigquery, ...) on@@ -17,7 +16,6 @@ from typing import TYPE_CHECKING, Anyif TYPE_CHECKING:from products.batch_exports.backend.temporal.metrics import BatchExportsMetricsInterceptor- from products.batch_exports.backend.temporal.noop import NoOpWorkflow, noop_activityfrom products.batch_exports.backend.temporal.workflows import ACTIVITIES, WORKFLOWS_B = "products.batch_exports.backend.temporal."@@ -26,16 +24,12 @@ _LAZY = {"ACTIVITIES": "workflows","WORKFLOWS": "workflows","BatchExportsMetricsInterceptor": "metrics",- "NoOpWorkflow": "noop",- "noop_activity": "noop",}__all__ = ["ACTIVITIES","WORKFLOWS","BatchExportsMetricsInterceptor",- "NoOpWorkflow",- "noop_activity",]diff --git a/products/batch_exports/backend/facade/testing.py b/products/batch_exports/backend/facade/testing.pyindex cc423acd1670..22147af8aaa9 100644--- a/products/batch_exports/backend/facade/testing.py+++ b/products/batch_exports/backend/facade/testing.py@@ -32,8 +32,6 @@ from .api import _to_backfill_summary, _to_detail, _to_run_summaryif TYPE_CHECKING:from temporalio.client import Client- from products.batch_exports.backend.service import NoOpInputs-def create_batch_export(team_id: int,@@ -198,14 +196,3 @@ def list_backfills("-created_at")[:limit]return [_to_backfill_summary(backfill) for backfill in backfills]---def build_noop_inputs(*, arg: str, team_id: int, batch_export_id: str) -> "NoOpInputs":- """Build the inputs of the no-op workflow, which core uses to exercise the payload codec.-- A builder rather than a re-export of the class: ``NoOpInputs`` lives in ``service.py``,- which is not a wiring location, so handing the class out would be a facade leak.- """- from products.batch_exports.backend.service import NoOpInputs-- return NoOpInputs(arg=arg, team_id=team_id, batch_export_id=batch_export_id)