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.

chore(batch-exports): move warehouse callers onto the facade (#109286)

Ross7b5d4f2893ad
diff --git a/products/batch_exports/backend/facade/api.py b/products/batch_exports/backend/facade/api.py
index e001e5d90acb..f6f3ec3e35b0 100644
--- a/products/batch_exports/backend/facade/api.py
+++ b/products/batch_exports/backend/facade/api.py
@@ -13,8 +13,9 @@ facade, so it reaches the service only through ``_service()``, which imports it
time. For the same reason the Temporal client is built in ``_get_temporal_client()``.
Temporal workflow and activity registration crosses as objects, not data, so it lives in
-``facade/temporal.py``; the pipeline internals the warehouse writers reuse live in
-``facade/pipeline.py``. Neither may be imported from here.
+``facade/temporal.py``. The destination clients the warehouse writers reuse live in
+``facade/destinations/``, and the stream transformers in ``facade/pipeline.py``. None of
+those may be imported from here.
"""
import datetime as dt
diff --git a/products/batch_exports/backend/facade/destinations/__init__.py b/products/batch_exports/backend/facade/destinations/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/products/batch_exports/backend/facade/destinations/azure_blob.py b/products/batch_exports/backend/facade/destinations/azure_blob.py
new file mode 100644
index 000000000000..3ff483c0ad0f
--- /dev/null
+++ b/products/batch_exports/backend/facade/destinations/azure_blob.py
@@ -0,0 +1,23 @@
+"""
+Azure Blob destination wiring for batch_exports.
+
+Re-exports the integration lookup, error helpers and compression list that the
+warehouse_sources Azure Blob writer reuses.
+
+Importing this module loads the destination's vendor SDK, so keep it off the
+``django.setup()`` path. See ``posthog/test/repo_invariants/test_startup_import_budget.py``.
+"""
+
+from products.batch_exports.backend.temporal.destinations.azure_blob_batch_export import (
+ MalformedConnectionStringError,
+ _get_azure_blob_integration as get_azure_blob_integration,
+ _is_authorization_failure_response_error as is_authorization_failure_response_error,
+)
+from products.batch_exports.backend.temporal.destinations.constants import AZURE_BLOB_SUPPORTED_COMPRESSIONS
+
+__all__ = [
+ "AZURE_BLOB_SUPPORTED_COMPRESSIONS",
+ "MalformedConnectionStringError",
+ "get_azure_blob_integration",
+ "is_authorization_failure_response_error",
+]
diff --git a/products/batch_exports/backend/facade/destinations/bigquery.py b/products/batch_exports/backend/facade/destinations/bigquery.py
new file mode 100644
index 000000000000..26dc3f5cecf8
--- /dev/null
+++ b/products/batch_exports/backend/facade/destinations/bigquery.py
@@ -0,0 +1,31 @@
+"""
+BigQuery destination wiring for batch_exports.
+
+Re-exports the BigQuery client that the warehouse_sources BigQuery writer reuses, and the
+service account helpers that let the BigQuery import source impersonate a customer's service
+account through the same PostHog identity that BigQuery batch exports use.
+
+The import source resolves credentials on web requests, so it imports this module inside the
+function that needs it.
+
+Importing this module loads the destination's vendor SDK, so keep it off the
+``django.setup()`` path. See ``posthog/test/repo_invariants/test_startup_import_budget.py``.
+"""
+
+from products.batch_exports.backend.temporal.destinations.bigquery_batch_export import (
+ BigQueryClient,
+ MissingRequiredPermissionsError,
+ ServiceAccountNotFoundError,
+ ServiceAccountOwnershipError,
+ get_our_google_cloud_credentials,
+ verify_impersonated_service_account_ownership,
+)
+
+__all__ = [
+ "BigQueryClient",
+ "MissingRequiredPermissionsError",
+ "ServiceAccountNotFoundError",
+ "ServiceAccountOwnershipError",
+ "get_our_google_cloud_credentials",
+ "verify_impersonated_service_account_ownership",
+]
diff --git a/products/batch_exports/backend/facade/destinations/databricks.py b/products/batch_exports/backend/facade/destinations/databricks.py
new file mode 100644
index 000000000000..1cc9f8f1b28e
--- /dev/null
+++ b/products/batch_exports/backend/facade/destinations/databricks.py
@@ -0,0 +1,29 @@
+"""
+Databricks destination wiring for batch_exports.
+
+Re-exports the client, the field type and the error handling that the warehouse_sources
+Databricks writer reuses.
+
+Importing this module loads the destination's vendor SDK, so keep it off the
+``django.setup()`` path. See ``posthog/test/repo_invariants/test_startup_import_budget.py``.
+"""
+
+from products.batch_exports.backend.temporal.destinations.databricks_batch_export import (
+ FIVE_MINUTES,
+ ONE_HOUR,
+ ONE_MINUTE,
+ DatabricksClient,
+ DatabricksField,
+ DatabricksIntegrationNotFoundError,
+ handle_common_errors,
+)
+
+__all__ = [
+ "DatabricksClient",
+ "DatabricksField",
+ "DatabricksIntegrationNotFoundError",
+ "FIVE_MINUTES",
+ "ONE_HOUR",
+ "ONE_MINUTE",
+ "handle_common_errors",
+]
diff --git a/products/batch_exports/backend/facade/destinations/postgres.py b/products/batch_exports/backend/facade/destinations/postgres.py
new file mode 100644
index 000000000000..ea585e1f8f97
--- /dev/null
+++ b/products/batch_exports/backend/facade/destinations/postgres.py
@@ -0,0 +1,23 @@
+"""
+Postgres destination wiring for batch_exports.
+
+Re-exports the client and the transaction helper that the warehouse_sources Postgres and
+Redshift writers reuse.
+
+Importing this module loads the destination's vendor SDK, so keep it off the
+``django.setup()`` path. See ``posthog/test/repo_invariants/test_startup_import_budget.py``.
+"""
+
+from products.batch_exports.backend.temporal.destinations.postgres_batch_export import (
+ Fields,
+ PostgreSQLClient,
+ PostgreSQLIntegrationNotFoundError,
+ run_in_retryable_transaction,
+)
+
+__all__ = [
+ "Fields",
+ "PostgreSQLClient",
+ "PostgreSQLIntegrationNotFoundError",
+ "run_in_retryable_transaction",
+]
diff --git a/products/batch_exports/backend/facade/destinations/redshift.py b/products/batch_exports/backend/facade/destinations/redshift.py
new file mode 100644
index 000000000000..0012ae9c3fe7
--- /dev/null
+++ b/products/batch_exports/backend/facade/destinations/redshift.py
@@ -0,0 +1,14 @@
+"""
+Redshift destination wiring for batch_exports.
+
+Re-exports the client that the warehouse_sources Redshift writer reuses.
+
+Importing this module loads the destination's vendor SDK, so keep it off the
+``django.setup()`` path. See ``posthog/test/repo_invariants/test_startup_import_budget.py``.
+"""
+
+from products.batch_exports.backend.temporal.destinations.redshift_batch_export import RedshiftClient
+
+__all__ = [
+ "RedshiftClient",
+]
diff --git a/products/batch_exports/backend/facade/destinations/s3.py b/products/batch_exports/backend/facade/destinations/s3.py
new file mode 100644
index 000000000000..3127fc81a486
--- /dev/null
+++ b/products/batch_exports/backend/facade/destinations/s3.py
@@ -0,0 +1,29 @@
+"""
+S3 destination wiring for batch_exports.
+
+Re-exports the client, the upload consumer and the credential helpers that the
+warehouse_sources S3 writer reuses.
+
+Importing this module loads the destination's vendor SDK, so keep it off the
+``django.setup()`` path. See ``posthog/test/repo_invariants/test_startup_import_budget.py``.
+"""
+
+from products.batch_exports.backend.temporal.destinations.constants import S3_SUPPORTED_COMPRESSIONS
+from products.batch_exports.backend.temporal.destinations.s3_batch_export import (
+ ConcurrentS3Consumer,
+ IntermittentUploadPartTimeoutError,
+ PolicyStatement,
+ _get_s3_integration as get_s3_integration,
+ get_credentials_using_user_aws_role,
+ s3_client,
+)
+
+__all__ = [
+ "ConcurrentS3Consumer",
+ "IntermittentUploadPartTimeoutError",
+ "PolicyStatement",
+ "S3_SUPPORTED_COMPRESSIONS",
+ "get_credentials_using_user_aws_role",
+ "get_s3_integration",
+ "s3_client",
+]
diff --git a/products/batch_exports/backend/facade/destinations/snowflake.py b/products/batch_exports/backend/facade/destinations/snowflake.py
new file mode 100644
index 000000000000..075f49977c61
--- /dev/null
+++ b/products/batch_exports/backend/facade/destinations/snowflake.py
@@ -0,0 +1,29 @@
+"""
+Snowflake destination wiring for batch_exports.
+
+Re-exports the client, the table types and the credential helpers that the warehouse_sources
+Snowflake writer reuses.
+
+Importing this module loads the destination's vendor SDK, so keep it off the
+``django.setup()`` path. See ``posthog/test/repo_invariants/test_startup_import_budget.py``.
+"""
+
+from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import (
+ NamedBytesIO,
+ SnowflakeClient,
+ SnowflakeField,
+ SnowflakeTable,
+ SnowflakeType,
+ _get_snowflake_integration as get_snowflake_integration,
+ load_private_key,
+)
+
+__all__ = [
+ "NamedBytesIO",
+ "SnowflakeClient",
+ "SnowflakeField",
+ "SnowflakeTable",
+ "SnowflakeType",
+ "get_snowflake_integration",
+ "load_private_key",
+]
diff --git a/products/batch_exports/backend/facade/models.py b/products/batch_exports/backend/facade/models.py
deleted file mode 100644
index 90d5bf5fbf14..000000000000
--- a/products/batch_exports/backend/facade/models.py
+++ /dev/null
@@ -1,14 +0,0 @@
-"""
-Model-class wiring for batch_exports.
-
-Re-exports the BatchExportRun model cross-product consumers read. Light (Django model).
-
-batch_exports is not on the watched-models allowance (``MODEL_CROSSINGS``), so this
-re-export is an unsanctioned crossing, not a sanctioned one. Its one consumer is the
-failed-runs block of the data_warehouse overview, which ``facade.api.list_latest_failed_runs``
-replaces. This module goes when that consumer moves.
-"""
-
-from products.batch_exports.backend.models.batch_export import BatchExportRun
-
-__all__ = ["BatchExportRun"]
diff --git a/products/batch_exports/backend/facade/pipeline.py b/products/batch_exports/backend/facade/pipeline.py
index b611ae4e9f55..80bad5c947a7 100644
--- a/products/batch_exports/backend/facade/pipeline.py
+++ b/products/batch_exports/backend/facade/pipeline.py
@@ -1,100 +1,17 @@
"""
Export-pipeline wiring for batch_exports.
-Re-exports the destination clients, stream transformers and credential helpers that the
-warehouse_sources Temporal writers reuse, so a data-import writer and a batch export talk
-to Snowflake, BigQuery, Databricks, Postgres, Redshift, S3 and Azure Blob the same way.
+Re-exports the stream transformers that the warehouse_sources Temporal writers reuse, so a
+data import and a batch export serialize records the same way. The destination clients live
+in ``facade/destinations/``, one module per destination.
-Every name here comes from ``backend/temporal/``, so importing this module pulls each
-destination's vendor SDK. Only Temporal activity code may import it. Never import it from
-``facade/api.py``, or from anything else on the ``django.setup()`` path — see
+Importing this module loads pyarrow, so keep it off the ``django.setup()`` path. See
``posthog/test/repo_invariants/test_startup_import_budget.py``.
"""
-from products.batch_exports.backend.temporal.destinations.azure_blob_batch_export import (
- MalformedConnectionStringError,
- _get_azure_blob_integration as get_azure_blob_integration,
- _is_authorization_failure_response_error as is_authorization_failure_response_error,
-)
-from products.batch_exports.backend.temporal.destinations.bigquery_batch_export import (
- BigQueryClient,
- verify_impersonated_service_account_ownership,
-)
-from products.batch_exports.backend.temporal.destinations.constants import (
- AZURE_BLOB_SUPPORTED_COMPRESSIONS,
- S3_SUPPORTED_COMPRESSIONS,
-)
-from products.batch_exports.backend.temporal.destinations.databricks_batch_export import (
- FIVE_MINUTES,
- ONE_HOUR,
- ONE_MINUTE,
- DatabricksClient,
- DatabricksField,
- DatabricksIntegrationNotFoundError,
- handle_common_errors,
-)
-from products.batch_exports.backend.temporal.destinations.postgres_batch_export import (
- Fields,
- PostgreSQLClient,
- PostgreSQLIntegrationNotFoundError,
- run_in_retryable_transaction,
-)
-from products.batch_exports.backend.temporal.destinations.redshift_batch_export import RedshiftClient
-from products.batch_exports.backend.temporal.destinations.s3_batch_export import (
- ConcurrentS3Consumer,
- IntermittentUploadPartTimeoutError,
- PolicyStatement,
- _get_s3_integration as get_s3_integration,
- get_credentials_using_user_aws_role,
- s3_client,
-)
-from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import (
- NamedBytesIO,
- SnowflakeClient,
- SnowflakeField,
- SnowflakeTable,
- SnowflakeType,
- _get_snowflake_integration as get_snowflake_integration,
- load_private_key,
-)
from products.batch_exports.backend.temporal.pipeline.transformer import CSVStreamTransformer, ParquetStreamTransformer
-from .contracts import AWSCredentials
-
__all__ = [
- "AWSCredentials",
- "AZURE_BLOB_SUPPORTED_COMPRESSIONS",
- "BigQueryClient",
"CSVStreamTransformer",
- "ConcurrentS3Consumer",
- "DatabricksClient",
- "DatabricksField",
- "DatabricksIntegrationNotFoundError",
- "FIVE_MINUTES",
- "Fields",
- "IntermittentUploadPartTimeoutError",
- "MalformedConnectionStringError",
- "NamedBytesIO",
- "ONE_HOUR",
- "ONE_MINUTE",
"ParquetStreamTransformer",
- "PolicyStatement",
- "PostgreSQLClient",
- "PostgreSQLIntegrationNotFoundError",
- "RedshiftClient",
- "S3_SUPPORTED_COMPRESSIONS",
- "SnowflakeClient",
- "SnowflakeField",
- "SnowflakeTable",
- "SnowflakeType",
- "get_azure_blob_integration",
- "get_credentials_using_user_aws_role",
- "get_s3_integration",
- "get_snowflake_integration",
- "handle_common_errors",
- "is_authorization_failure_response_error",
- "load_private_key",
- "run_in_retryable_transaction",
- "s3_client",
- "verify_impersonated_service_account_ownership",
]
diff --git a/products/data_warehouse/backend/presentation/views/data_warehouse.py b/products/data_warehouse/backend/presentation/views/data_warehouse.py
index 764359164455..9af996ff7174 100644
--- a/products/data_warehouse/backend/presentation/views/data_warehouse.py
+++ b/products/data_warehouse/backend/presentation/views/data_warehouse.py
@@ -34,7 +34,7 @@ from posthog.permissions import is_service_auth
from posthog.utils import convert_property_value, flatten
from products.access_control.backend.facade.user_access_control import access_level_satisfied_for_resource
-from products.batch_exports.backend.facade.models import BatchExportRun
+from products.batch_exports.backend.facade import api as batch_exports_api
from products.cdp.backend.facade.models import HogFunction, HogFunctionState, HogFunctionType
from products.data_modeling.backend.facade.models import DataModelingJob, DataModelingJobEngine, DataWarehouseSavedQuery
from products.data_quality.backend.presentation.serializers import DataQualityGateConfigSerializer
@@ -964,41 +964,16 @@ class DataWarehouseViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
}
)
- # Get failed batch exports
- # get latest run per export, then filter for failures
- # Exclude paused exports since their last failure is no longer actionable
- latest_run_ids = (
- BatchExportRun.objects.filter(
- batch_export__team_id=self.team_id,
- batch_export__deleted=False,
- batch_export__paused=False,
- )
- .order_by("batch_export_id", "-created_at")
- .distinct("batch_export_id")
- .values_list("id", flat=True)
- )
-
- # nosemgrep: idor-lookup-without-team (IDs from team-scoped queryset)
- failed_runs = BatchExportRun.objects.filter(
- id__in=latest_run_ids,
- status__in=[
- BatchExportRun.Status.FAILED,
- BatchExportRun.Status.FAILED_RETRYABLE,
- BatchExportRun.Status.TIMEDOUT,
- BatchExportRun.Status.TERMINATED,
- ],
- ).select_related("batch_export")
-
- for run in failed_runs:
+ for failed_run in batch_exports_api.list_latest_failed_runs(self.team_id):
results.append(
{
- "id": str(run.parent.id),
- "name": getattr(run.parent, "name", "Batch export on demand"),
+ "id": str(failed_run.export_id),
+ "name": failed_run.export_name,
"type": "destination",
"status": "failed",
- "error": run.latest_error,
- "failed_at": run.finished_at.isoformat() if run.finished_at else None,
- "url": f"/pipeline/batch-exports/{run.parent.id}",
+ "error": failed_run.error,
+ "failed_at": failed_run.failed_at.isoformat() if failed_run.failed_at else None,
+ "url": f"/pipeline/batch-exports/{failed_run.export_id}",
}
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/destinations/registry.py b/products/warehouse_sources/backend/temporal/data_imports/destinations/registry.py
index 27f520572bf3..e358003d3b41 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/destinations/registry.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/destinations/registry.py
@@ -1,10 +1,10 @@
"""Where destination writers are looked up by type.
The external destinations (Redshift, Snowflake, BigQuery, ...) are implemented on top of
-batch exports' destination clients and transformers, which warehouse_sources depends on
-directly (see tach.toml). Writers are still resolved by type string rather than imported at
-the call site, so the processor never names a destination type and a driver only loads when
-a destination of that type is actually written to.
+batch exports' destination clients and transformers, which warehouse_sources reads through
+batch exports' ``facade.destinations`` package. Writers are still resolved by type string
+rather than imported at the call site, so the processor never names a destination type and a
+driver only loads when a destination of that type is actually written to.
An unregistered type raises rather than degrading to a no-op: silently writing nothing to a
destination a customer configured, and billing it, is worse than failing the batch.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_databricks.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_databricks.py
index 666b98b1ddaf..febdc19345cd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_databricks.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_databricks.py
@@ -20,7 +20,7 @@ from typing import Any
import pyarrow as pa
import pyarrow.parquet as pq
-from products.batch_exports.backend.temporal.destinations.databricks_batch_export import DatabricksField
+from products.batch_exports.backend.facade.destinations.databricks import DatabricksField
_INFORMATION_SCHEMA_TABLES = re.compile(r"information_schema\.tables", re.IGNORECASE)
_TABLE_NAME_PREDICATE = re.compile(r"table_name\)?\s*=\s*'([^']*)'", re.IGNORECASE)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_snowflake.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_snowflake.py
index 5efc5d631fc1..f48167cf6c79 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_snowflake.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/fake_snowflake.py
@@ -19,7 +19,7 @@ from typing import Any
import pyarrow as pa
import pyarrow.parquet as pq
-from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import NamedBytesIO, SnowflakeTable
+from products.batch_exports.backend.facade.destinations.snowflake import NamedBytesIO, SnowflakeTable
_CREATE_SCHEMA = re.compile(r'^CREATE SCHEMA IF NOT EXISTS "([^"]+)"', re.IGNORECASE)
_CREATE_TABLE = re.compile(r'^CREATE TABLE IF NOT EXISTS "[^"]+"\."([^"]+)"\s*\((.*)\)$', re.IGNORECASE | re.DOTALL)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_databricks_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_databricks_writer.py
index 3f204f406099..c33235c81563 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_databricks_writer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_databricks_writer.py
@@ -5,7 +5,7 @@ import pytest
import pyarrow as pa
from parameterized import parameterized
-from products.batch_exports.backend.temporal.destinations.databricks_batch_export import DatabricksClient
+from products.batch_exports.backend.facade.destinations.databricks import DatabricksClient
from products.warehouse_sources.backend.temporal.data_imports.destinations.contracts import (
DestinationBatchContext,
DestinationRunContext,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_postgres_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_postgres_writer.py
index bb811f1f1281..abc1e1285eb9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_postgres_writer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_postgres_writer.py
@@ -9,7 +9,7 @@ import psycopg
import pyarrow as pa
import psycopg.conninfo
-from products.batch_exports.backend.temporal.destinations.postgres_batch_export import PostgreSQLClient
+from products.batch_exports.backend.facade.destinations.postgres import PostgreSQLClient
from products.warehouse_sources.backend.temporal.data_imports.destinations.contracts import (
DestinationBatchContext,
DestinationRunContext,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_snowflake_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_snowflake_writer.py
index 82c58099de1f..8ad0cea66f14 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_snowflake_writer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/tests/test_snowflake_writer.py
@@ -5,7 +5,7 @@ import pytest
import pyarrow as pa
from parameterized import parameterized
-from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import SnowflakeClient
+from products.batch_exports.backend.facade.destinations.snowflake import SnowflakeClient
from products.warehouse_sources.backend.temporal.data_imports.destinations.contracts import (
DestinationBatchContext,
DestinationRunContext,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/azure_blob.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/azure_blob.py
index eec7a7b90f02..a805a7f5c3aa 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/azure_blob.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/azure_blob.py
@@ -19,7 +19,7 @@ Connection handling comes from batch exports' Azure Blob destination:
aim the client at an internal address.
- The client tuning is theirs too. `read_timeout` is the one that matters: the SDK default is
60 seconds, which a single large block can exceed on a slow link.
-- `_is_authorization_failure_response_error` is what separates "the credentials cannot write
+- `is_authorization_failure_response_error` is what separates "the credentials cannot write
here" from a transient response error, so the first is reported as a permissions problem.
`AzureBlobConsumer` itself is not used, even though it touches no Temporal metric meter and so
@@ -49,13 +49,13 @@ from azure.storage.blob.aio import BlobServiceClient, ContainerClient, Exponenti
from posthog.models.integration.azure_blob import EndpointNotAllowedError, validate_azure_blob_connection_string
-from products.batch_exports.backend.temporal.destinations.azure_blob_batch_export import (
+from products.batch_exports.backend.facade.destinations.azure_blob import (
+ AZURE_BLOB_SUPPORTED_COMPRESSIONS,
MalformedConnectionStringError,
- _get_azure_blob_integration,
- _is_authorization_failure_response_error,
+ get_azure_blob_integration,
+ is_authorization_failure_response_error,
)
-from products.batch_exports.backend.temporal.destinations.constants import AZURE_BLOB_SUPPORTED_COMPRESSIONS
-from products.batch_exports.backend.temporal.pipeline.transformer import ParquetStreamTransformer
+from products.batch_exports.backend.facade.pipeline import ParquetStreamTransformer
from products.warehouse_sources.backend.temporal.data_imports.destinations.contracts import (
BatchWriteOutcome,
DestinationBatchContext,
@@ -209,7 +209,7 @@ class AzureBlobDestinationWriter:
if self._ctx.integration_id is None:
raise ValueError(f"Destination {self._ctx.destination_name} has no integration to connect with")
- integration = await _get_azure_blob_integration(self._ctx.integration_id, self._ctx.team_id)
+ integration = await get_azure_blob_integration(self._ctx.integration_id, self._ctx.team_id)
try:
await asyncio.to_thread(validate_azure_blob_connection_string, integration.connection_string)
@@ -237,7 +237,7 @@ class AzureBlobDestinationWriter:
except ResourceNotFoundError:
raise ContainerNotFoundError(self._container)
except HttpResponseError as err:
- if _is_authorization_failure_response_error(err):
+ if is_authorization_failure_response_error(err):
raise MissingContainerPermissionsError(self._container)
raise
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/bigquery.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/bigquery.py
index bd1b89323e2e..c05454dfbfcf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/bigquery.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/bigquery.py
@@ -24,7 +24,7 @@ from google.cloud import bigquery
from posthog.models.integration.google_cloud import GoogleCloudServiceAccountIntegration
-from products.batch_exports.backend.temporal.destinations.bigquery_batch_export import (
+from products.batch_exports.backend.facade.destinations.bigquery import (
BigQueryClient,
verify_impersonated_service_account_ownership,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/databricks.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/databricks.py
index c32915f36567..86b6484cbb54 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/databricks.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/databricks.py
@@ -30,7 +30,7 @@ import pyarrow.parquet as pq
from posthog.models.integration import Integration
from posthog.models.integration.databricks import DatabricksIntegration
-from products.batch_exports.backend.temporal.destinations.databricks_batch_export import (
+from products.batch_exports.backend.facade.destinations.databricks import (
FIVE_MINUTES,
ONE_HOUR,
ONE_MINUTE,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/postgres.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/postgres.py
index 706522ba327c..bec29759ffdd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/postgres.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/postgres.py
@@ -38,13 +38,13 @@ from psycopg import sql
from posthog.models.integration import Integration, PostgreSQLIntegration
-from products.batch_exports.backend.temporal.destinations.postgres_batch_export import (
+from products.batch_exports.backend.facade.destinations.postgres import (
Fields,
PostgreSQLClient,
PostgreSQLIntegrationNotFoundError,
run_in_retryable_transaction,
)
-from products.batch_exports.backend.temporal.pipeline.transformer import CSVStreamTransformer
+from products.batch_exports.backend.facade.pipeline import CSVStreamTransformer
from products.warehouse_sources.backend.temporal.data_imports.destinations.contracts import (
BatchWriteOutcome,
DestinationBatchContext,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/redshift.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/redshift.py
index 5b5ce19ea77c..a9c40922a9c1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/redshift.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/redshift.py
@@ -29,8 +29,8 @@ from psycopg import sql
from posthog.models.integration import Integration, RedshiftIntegration
-from products.batch_exports.backend.temporal.destinations.postgres_batch_export import Fields, PostgreSQLClient
-from products.batch_exports.backend.temporal.destinations.redshift_batch_export import RedshiftClient
+from products.batch_exports.backend.facade.destinations.postgres import Fields, PostgreSQLClient
+from products.batch_exports.backend.facade.destinations.redshift import RedshiftClient
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.destinations_load.writers.postgres import (
PostgresDestinationWriter,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/s3.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/s3.py
index 8595bfe4dc6a..3429daa12ede 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/s3.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/s3.py
@@ -13,7 +13,7 @@ the stamp exists to cover there.
Credentials, the client and its config come from batch exports' S3 destination:
-- `_get_s3_integration` resolves all three shapes an S3-family integration can take. A
+- `get_s3_integration` resolves all three shapes an S3-family integration can take. A
role-based AWS integration keeps `aws_role_arn` in `config` with an empty `sensitive_config`,
so reading key credentials off it raises. The AssumeRole flow behind it
(`get_credentials_using_user_aws_role`) also refuses a role whose policy has no external-id
@@ -52,17 +52,17 @@ import botocore.exceptions
from posthog.models.integration import AWSS3RoleBasedIntegration, S3CompatibleIntegration
from posthog.models.team import Team
-from products.batch_exports.backend.service import AWSCredentials
-from products.batch_exports.backend.temporal.destinations.constants import S3_SUPPORTED_COMPRESSIONS
-from products.batch_exports.backend.temporal.destinations.s3_batch_export import (
+from products.batch_exports.backend.facade.contracts import AWSCredentials
+from products.batch_exports.backend.facade.destinations.s3 import (
+ S3_SUPPORTED_COMPRESSIONS,
ConcurrentS3Consumer,
IntermittentUploadPartTimeoutError,
PolicyStatement,
- _get_s3_integration,
get_credentials_using_user_aws_role,
+ get_s3_integration,
s3_client,
)
-from products.batch_exports.backend.temporal.pipeline.transformer import ParquetStreamTransformer
+from products.batch_exports.backend.facade.pipeline import ParquetStreamTransformer
from products.warehouse_sources.backend.temporal.data_imports.destinations.contracts import (
BatchWriteOutcome,
DestinationBatchContext,
@@ -308,7 +308,7 @@ class S3DestinationWriter:
if self._ctx.integration_id is None:
raise ValueError(f"Destination {self._ctx.destination_name} has no integration to connect with")
- integration = await _get_s3_integration(self._ctx.integration_id, self._ctx.team_id)
+ integration = await get_s3_integration(self._ctx.integration_id, self._ctx.team_id)
endpoint_url: str | None = None
refresh_credentials: RefreshCredentials | None = None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/snowflake.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/snowflake.py
index f7df352e154a..9f21cc8c8ecf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/snowflake.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/destinations_load/writers/snowflake.py
@@ -30,13 +30,13 @@ from typing import ClassVar
import pyarrow as pa
import pyarrow.parquet as pq
-from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import (
+from products.batch_exports.backend.facade.destinations.snowflake import (
NamedBytesIO,
SnowflakeClient,
SnowflakeField,
SnowflakeTable,
SnowflakeType,
- _get_snowflake_integration,
+ get_snowflake_integration,
load_private_key,
)
from products.warehouse_sources.backend.temporal.data_imports.destinations.contracts import (
@@ -219,7 +219,7 @@ class SnowflakeDestinationWriter:
if self._ctx.integration_id is None:
raise ValueError(f"Destination {self._ctx.destination_name} has no integration to connect with")
- creds = await _get_snowflake_integration(self._ctx.integration_id, self._ctx.team_id)
+ creds = await get_snowflake_integration(self._ctx.integration_id, self._ctx.team_id)
private_key: bytes | None = None
password: str | None = None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
index 3ab44fff72ec..f3e3f1da9ce9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
@@ -520,7 +520,7 @@ def _impersonated_credentials(service_account_email: str, team_id: int) -> googl
"""
# Imported here so the source registry — which the API imports on every request path — does not
# pull in the batch-export Temporal module.
- from products.batch_exports.backend.temporal.destinations.bigquery_batch_export import ( # noqa: PLC0415 — keeps the batch-export Temporal module off the source registry's import path
+ from products.batch_exports.backend.facade.destinations.bigquery import ( # noqa: PLC0415 — keeps the batch-export Temporal module off the source registry's import path
MissingRequiredPermissionsError,
ServiceAccountNotFoundError,
ServiceAccountOwnershipError,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
index 440e9fb08fe2..535e3f986a0f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -23,7 +23,7 @@ from requests.adapters import HTTPAdapter
from posthog.models.integration import Integration
from posthog.models.team.team import Team
-from products.batch_exports.backend.temporal.destinations.bigquery_batch_export import ServiceAccountOwnershipError
+from products.batch_exports.backend.facade.destinations.bigquery import ServiceAccountOwnershipError
from products.warehouse_sources.backend.temporal.data_imports.sources.bigquery import bigquery as bq_module
from products.warehouse_sources.backend.temporal.data_imports.sources.bigquery.bigquery import (
BIGQUERY_CREATE_READ_SESSION_RETRY,
@@ -2327,7 +2327,7 @@ def test_bigquery_build_pipeline_threads_resolved_rest_api_version(pin):
# every client the run opens signs with what it returns.
-_BATCH_EXPORT_MODULE = "products.batch_exports.backend.temporal.destinations.bigquery_batch_export"
+_BATCH_EXPORT_MODULE = "products.batch_exports.backend.facade.destinations.bigquery"
def _google_cloud_integration(team, *, with_key: bool, email: str = "[email protected]"):
diff --git a/tach.toml b/tach.toml
index 52e83cb5d7e4..19c7e6aeb385 100644
--- a/tach.toml
+++ b/tach.toml
@@ -1302,21 +1302,13 @@ from = [
"products.batch_exports",
]
-# Legacy leaks — cdp and warehouse_sources still import these batch_exports internals
-# directly. Each entry names its crossing and the facade that replaces it. The block
-# drains as those callers move, and keeps backend:contract-check off until it is empty.
+# Legacy leaks — cdp still imports these batch_exports internals directly. Each entry names
+# its crossing and the facade that replaces it. The block drains as those callers move, and
+# keeps backend:contract-check off until it is empty.
# tach interfaces have no consumer scoping, so this block opens the listed paths to every module,
# not only to the consumers named below.
[[interfaces]]
expose = [
- # The warehouse_sources S3 writer reads AWSCredentials from the service layer.
- # Exit: facade.pipeline.
- "backend\\.service.*",
- # The warehouse_sources data-import writers reuse the destination clients and the stream
- # transformers.
- # Exit: facade.pipeline.
- "backend\\.temporal\\.destinations.*",
- "backend\\.temporal\\.pipeline\\.transformer.*",
# cdp's enable_backfills validates with BatchExportSerializer. A facade must not import DRF,
# so the exit here is the presentation move, after which presentation.views is the channel.
"backend\\.api\\.batch_export.*",