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): resolve snowflake credentials from the integration only (#101090)

Rossc32655a66ddc
diff --git a/products/batch_exports/backend/api/batch_export.py b/products/batch_exports/backend/api/batch_export.py
index 492d7cf16109..9f31f5fca682 100644
--- a/products/batch_exports/backend/api/batch_export.py
+++ b/products/batch_exports/backend/api/batch_export.py
@@ -481,11 +481,6 @@ class S3CompatibleDestinationConfigSerializer(S3FamilyDestinationConfigSerialize
)
-SNOWFLAKE_CREDENTIAL_FIELDS = frozenset(
- {"account", "user", "authentication_type", "password", "private_key", "private_key_passphrase"}
-)
-
-
class SnowflakeDestinationConfigSerializer(serializers.Serializer):
"""Typed configuration for a Snowflake batch-export destination.
@@ -1369,13 +1364,6 @@ class BatchExportSerializer(serializers.ModelSerializer):
raise serializers.ValidationError(f"Invalid destination URL: {url}")
if destination_type == BatchExportDestination.Destination.SNOWFLAKE:
- # Still declared on `SnowflakeBatchExportInputs`, so the generic unknown-field check
- # lets them through. Raise its message, so dropping them there changes no error text.
- inline_credentials = sorted(config.keys() & SNOWFLAKE_CREDENTIAL_FIELDS)
- if inline_credentials:
- str_fields = ", ".join(f"'{field}'" for field in inline_credentials)
- raise serializers.ValidationError(f"Configuration has unknown field/s: {str_fields}")
-
integration: Integration | None = destination_attrs.get("integration")
if integration is None and "integration" not in destination_attrs and instance is not None:
# A PATCH may send config alone, which keeps the export's existing integration.
diff --git a/products/batch_exports/backend/service.py b/products/batch_exports/backend/service.py
index d4bfd9a00e48..6d9928780e13 100644
--- a/products/batch_exports/backend/service.py
+++ b/products/batch_exports/backend/service.py
@@ -358,21 +358,14 @@ class FileDownloadBatchExportInputs(BaseBatchExportInputs):
class SnowflakeBatchExportInputs(BaseBatchExportInputs):
"""Inputs for Snowflake export workflow.
- account, user, authentication_type and the credential fields are optional here:
- integration-backed exports resolve them from the linked Integration at run time (see
- `integration_id`), while legacy exports carry them inline.
+ Credentials are never carried here: the activity resolves them from the linked Integration at
+ run time (see `integration_id`).
"""
database: str
warehouse: str
schema: str
- account: str | None = None
- user: str | None = None
table_name: str = "events"
- authentication_type: str = "password"
- password: str | None = field(default=None, repr=False)
- private_key: str | None = field(default=None, repr=False)
- private_key_passphrase: str | None = field(default=None, repr=False)
role: str | None = None
diff --git a/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py b/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
index 077188bacd34..b6c02caa3103 100644
--- a/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
@@ -112,6 +112,8 @@ NON_RETRYABLE_ERROR_TYPES = (
"SnowflakeWarehouseUsageError",
# The linked Integration was deleted or doesn't belong to the team.
"SnowflakeIntegrationNotFoundError",
+ # Raised when an export has no linked integration, so it cannot authenticate at all.
+ "SnowflakeIntegrationRequiredError",
# The linked Integration is the wrong kind or has invalid/missing credentials.
"SnowflakeIntegrationError",
)
@@ -179,6 +181,16 @@ class SnowflakeIntegrationNotFoundError(Exception):
super().__init__(f"Snowflake integration with ID '{integration_id}' not found for team '{team_id}'")
+class SnowflakeIntegrationRequiredError(Exception):
+ """Raised when a Snowflake export runs without a linked Integration to authenticate with."""
+
+ def __init__(self, batch_export_id: str | None):
+ super().__init__(
+ f"Snowflake batch export '{batch_export_id}' has no linked integration. "
+ "Edit the export and choose a Snowflake connection."
+ )
+
+
async def _get_snowflake_integration(integration_id: int, team_id: int) -> SnowflakeIntegration:
"""Fetch a Snowflake integration from the database.
@@ -471,25 +483,19 @@ class SnowflakeTable(Table):
@dataclasses.dataclass(frozen=False, kw_only=True)
class SnowflakeInsertInputs(BatchExportInsertInputs):
- """Inputs for Snowflake."""
+ """Inputs for Snowflake.
- # TODO: do _not_ store credentials in temporal inputs. It makes it very hard
- # to keep track of where credentials are being stored and increases the
- # attach surface for credential leaks.
+ Credentials are resolved from the linked Integration in the activity, so they never enter a
+ Temporal payload.
+ """
database: str
warehouse: str
schema: str
table_name: str
- # When set, account/user/authentication_type and credentials are resolved from this Integration
- # at run time; otherwise the inline values below are used (legacy path).
+ # Optional so a schedule payload synced before the field existed converts cleanly. The activity
+ # raises `SnowflakeIntegrationRequiredError` when it is missing.
integration_id: int | None = None
- user: str | None = None
- account: str | None = None
- authentication_type: str = "password"
- password: str | None = dataclasses.field(default=None, repr=False)
- private_key: str | None = dataclasses.field(default=None, repr=False)
- private_key_passphrase: str | None = dataclasses.field(default=None, repr=False)
role: str | None = None
@@ -576,37 +582,29 @@ class SnowflakeClient:
self.logger = LOGGER.bind(user=user, account=account, warehouse=warehouse, database=database)
@classmethod
- def from_inputs(cls, inputs: SnowflakeInsertInputs) -> typing.Self:
- """Initialize `SnowflakeClient` from `SnowflakeInsertInputs`."""
-
- # account and user are optional on the inputs (integration-backed exports resolve them at run
- # time in the activity), but they must be resolved by the time we open a connection.
- account = inputs.account
- user = inputs.user
- if account is None or user is None:
- raise SnowflakeAuthenticationError("Snowflake account and user are required")
-
- # User could have specified both password and private key in their batch export config.
- # (for example, if they've already created a batch export with password auth and are now switching to keypair auth)
- # Therefore we decide which one to use based on the authentication_type.
+ def from_integration(cls, integration: SnowflakeIntegration, inputs: SnowflakeInsertInputs) -> typing.Self:
+ """Initialize `SnowflakeClient` from a resolved Integration and the export's inputs."""
+
+ # An integration can hold both a password and a private key, for instance after a rotation
+ # from one to the other, so its authentication_type decides which one to use.
password = None
private_key = None
- if inputs.authentication_type == "password":
- password = inputs.password
+ if integration.authentication_type == "password":
+ password = integration.password
if password is None:
raise SnowflakeAuthenticationError("Password is required for password authentication")
- elif inputs.authentication_type == "keypair":
- if inputs.private_key is None:
+ elif integration.authentication_type == "keypair":
+ if integration.private_key is None:
raise SnowflakeAuthenticationError("Private key is required for keypair authentication")
- private_key = load_private_key(inputs.private_key, inputs.private_key_passphrase)
+ private_key = load_private_key(integration.private_key, integration.private_key_passphrase)
else:
- raise SnowflakeAuthenticationError(f"Invalid authentication type: {inputs.authentication_type}")
+ raise SnowflakeAuthenticationError(f"Invalid authentication type: {integration.authentication_type}")
return cls(
- user=user,
- account=account,
+ user=integration.user,
+ account=integration.account,
warehouse=inputs.warehouse,
database=inputs.database,
schema=inputs.schema,
@@ -1411,17 +1409,10 @@ async def insert_into_snowflake_activity_from_stage(
)
async with Heartbeater():
- # Integration-backed exports resolve account, user, auth type and credentials at run time;
- # legacy exports carry them inline.
- # TODO: require integration
- if inputs.integration_id is not None:
- integration = await _get_snowflake_integration(inputs.integration_id, inputs.team_id)
- inputs.account = integration.account
- inputs.user = integration.user
- inputs.authentication_type = integration.authentication_type
- inputs.password = integration.password
- inputs.private_key = integration.private_key
- inputs.private_key_passphrase = integration.private_key_passphrase
+ if inputs.integration_id is None:
+ raise SnowflakeIntegrationRequiredError(inputs.batch_export_id)
+
+ integration = await _get_snowflake_integration(inputs.integration_id, inputs.team_id)
model: BatchExportModel | BatchExportSchema | None = None
if inputs.batch_export_schema is None:
@@ -1493,7 +1484,7 @@ async def insert_into_snowflake_activity_from_stage(
dt.datetime.fromisoformat(inputs.data_interval_end),
)
- async with SnowflakeClient.from_inputs(inputs).connect() as snow_client:
+ async with SnowflakeClient.from_integration(integration, inputs).connect() as snow_client:
consumer_table = snow_target_table = await snow_client.get_or_create_table(target_table)
# Exporting directly to target table
should_delete = False
@@ -1618,12 +1609,6 @@ class SnowflakeBatchExportWorkflow(PostHogWorkflow):
insert_inputs = SnowflakeInsertInputs(
team_id=inputs.team_id,
integration_id=inputs.integration_id,
- user=inputs.user,
- account=inputs.account,
- authentication_type=inputs.authentication_type,
- password=inputs.password,
- private_key=inputs.private_key,
- private_key_passphrase=inputs.private_key_passphrase,
warehouse=inputs.warehouse,
database=inputs.database,
schema=inputs.schema,
diff --git a/products/batch_exports/backend/tests/api/test_create.py b/products/batch_exports/backend/tests/api/test_create.py
index b41cdbc1c792..8a70c79653be 100644
--- a/products/batch_exports/backend/tests/api/test_create.py
+++ b/products/batch_exports/backend/tests/api/test_create.py
@@ -591,14 +591,10 @@ def test_create_batch_export_fails_with_invalid_query(
(
"Snowflake",
{
- "account": "my-account",
- "user": "user",
"database": "my-db",
"warehouse": "COMPUTE_WH",
"schema": "public",
"table_name": 2, # Wrong type
- "authentication_type": "keypair",
- "private_key": "SECRET_KEY",
},
"invalid type: got 'int', expected 'str'",
),
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/conftest.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/conftest.py
index 2174ea746610..942360f90865 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/conftest.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/conftest.py
@@ -1,4 +1,5 @@
import os
+import typing as t
import tempfile
from collections.abc import AsyncGenerator
from uuid import uuid4
@@ -8,6 +9,7 @@ import pytest
import pytest_asyncio
import snowflake.connector
+from posthog.models.integration import Integration, SnowflakeIntegration
from posthog.temporal.tests.utils.models import acreate_batch_export, adelete_batch_export
from products.batch_exports.backend.models.batch_export import BatchExport
@@ -66,14 +68,64 @@ def snowflake_config(database, schema) -> dict[str, str | None]:
return config
+def snowflake_export_config(snowflake_config) -> dict[str, str | None]:
+ return {key: snowflake_config[key] for key in ("warehouse", "database", "schema", "role")}
+
+
+def snowflake_integration_credentials(snowflake_config) -> SnowflakeIntegration:
+ """The credentials a Snowflake export authenticates with, on an unsaved Integration.
+
+ Enough for tests that only open a connection; use `snowflake_integration` where the code under
+ test looks the row up by id.
+ """
+ return SnowflakeIntegration(
+ Integration(
+ kind=Integration.IntegrationKind.SNOWFLAKE,
+ integration_id="test-snowflake",
+ config={
+ "name": "test-snowflake",
+ "account": snowflake_config["account"],
+ "user": snowflake_config["user"],
+ "authentication_type": snowflake_config["authentication_type"],
+ },
+ sensitive_config={
+ key: snowflake_config[key]
+ for key in ("password", "private_key", "private_key_passphrase")
+ if snowflake_config.get(key) is not None
+ },
+ )
+ )
+
+
+@pytest_asyncio.fixture
+async def snowflake_integration(ateam, snowflake_integration_credentials) -> AsyncGenerator[Integration]:
+ """The same credentials, saved, for tests that resolve the integration by id."""
+ integration = snowflake_integration_credentials.integration
+ integration.team = ateam
+ await integration.asave()
+
+ yield integration
+
+ await integration.adelete()
+
+
+@pytest_asyncio.fixture
+async def snowflake_activity_inputs(snowflake_export_config, snowflake_integration) -> dict[str, t.Any]:
+ """The destination fields of `SnowflakeInsertInputs`, pointing at the credentials integration."""
+ return {**snowflake_export_config, "integration_id": snowflake_integration.id}
+
+
@pytest_asyncio.fixture
async def snowflake_batch_export(
- ateam, table_name, snowflake_config, interval, exclude_events, temporal_client
+ ateam, table_name, snowflake_export_config, snowflake_integration, interval, exclude_events, temporal_client
) -> AsyncGenerator[BatchExport]:
"""Manage BatchExport model (and associated Temporal Schedule) for tests"""
destination_data = {
"type": "Snowflake",
- "config": {**snowflake_config, "table_name": table_name, "exclude_events": exclude_events},
+ "config": {**snowflake_export_config, "table_name": table_name, "exclude_events": exclude_events},
+ "integration_id": snowflake_integration.id,
}
batch_export_data = {
"name": "my-production-snowflake-export",
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity.py
index 32a742c90b6d..0da142e4204b 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity.py
@@ -3,13 +3,18 @@
These don't touch a real Snowflake instance, so (unlike test_activity_e2e.py) they run in CI.
"""
+import uuid
+
import pytest
from posthog.models.integration import Integration
from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import (
+ SnowflakeInsertInputs,
SnowflakeIntegrationNotFoundError,
+ SnowflakeIntegrationRequiredError,
_get_snowflake_integration,
+ insert_into_snowflake_activity_from_stage,
)
pytestmark = [pytest.mark.asyncio, pytest.mark.django_db]
@@ -35,3 +40,26 @@ async def test_get_snowflake_integration_ignores_wrong_kind(ateam):
)
with pytest.raises(SnowflakeIntegrationNotFoundError):
await _get_snowflake_integration(integration.id, ateam.pk)
+
+
+async def test_insert_activity_fails_when_export_has_no_integration(activity_environment, ateam):
+ """An export with no linked integration cannot authenticate, so the run fails before connecting.
+
+ The returned error also proves the failure is non-retryable: a retryable one re-raises instead,
+ and retrying cannot supply credentials the export does not have.
+ """
+ inputs = SnowflakeInsertInputs(
+ team_id=ateam.pk,
+ batch_export_id=str(uuid.uuid4()),
+ data_interval_start="2023-12-31T23:00:00+00:00",
+ data_interval_end="2024-01-01T00:00:00+00:00",
+ database="db",
+ warehouse="wh",
+ schema="public",
+ table_name="events",
+ )
+
+ result = await activity_environment.run(insert_into_snowflake_activity_from_stage, inputs)
+
+ assert result.error is not None
+ assert result.error.type == SnowflakeIntegrationRequiredError.__name__
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity_e2e.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity_e2e.py
index 31c511c31f7a..101391c29ad9 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity_e2e.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_activity_e2e.py
@@ -14,7 +14,6 @@ import pytest
from django.test import override_settings
-from posthog.models.integration import Integration
from posthog.temporal.tests.utils.events import generate_test_events_in_clickhouse
from products.batch_exports.backend.service import BatchExportModel, BatchExportSchema
@@ -50,7 +49,7 @@ async def _run_activity(
activity_environment,
snowflake_cursor,
clickhouse_client,
- snowflake_config,
+ snowflake_activity_inputs,
team,
data_interval_start,
data_interval_end,
@@ -67,16 +66,9 @@ async def _run_activity(
uppercase_columns: list[str] | None = None,
extra_fields: dict[str, t.Any] | None = None,
min_ingested_timestamp: dt.datetime | None = None,
- integration_id: int | None = None,
batch_export_id: str | None = None,
):
"""Helper function to run insert_into_snowflake_activity_from_stage and assert records in Snowflake"""
- config = dict(snowflake_config)
- if integration_id is not None:
- # Account, user and credentials come from the Integration, not inline config.
- for key in ("account", "user", "authentication_type", "password", "private_key", "private_key_passphrase"):
- config.pop(key, None)
-
insert_inputs = SnowflakeInsertInputs(
team_id=team.pk,
table_name=table_name,
@@ -86,8 +78,7 @@ async def _run_activity(
batch_export_schema=batch_export_schema,
batch_export_model=batch_export_model,
batch_export_id=batch_export_id or str(uuid.uuid4()),
- integration_id=integration_id,
- **config,
+ **snowflake_activity_inputs,
)
assert insert_inputs.batch_export_id is not None
@@ -140,7 +131,7 @@ async def test_insert_into_snowflake_activity_inserts_data_into_snowflake_table(
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
exclude_events,
model: BatchExportModel | BatchExportSchema | None,
generate_test_data,
@@ -187,7 +178,7 @@ async def test_insert_into_snowflake_activity_inserts_data_into_snowflake_table(
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -200,63 +191,11 @@ async def test_insert_into_snowflake_activity_inserts_data_into_snowflake_table(
)
-async def test_insert_into_snowflake_activity_resolves_credentials_from_integration(
- clickhouse_client,
- activity_environment,
- snowflake_cursor,
- snowflake_config,
- generate_test_data,
- data_interval_start,
- data_interval_end,
- ateam,
-):
- """An integration-backed export resolves account, user and credentials from the linked Integration
- at run time, with none of them present on the activity inputs.
- """
- sensitive_config: dict[str, str] = {}
- if snowflake_config["authentication_type"] == "keypair":
- sensitive_config["private_key"] = snowflake_config["private_key"]
- if snowflake_config.get("private_key_passphrase"):
- sensitive_config["private_key_passphrase"] = snowflake_config["private_key_passphrase"]
- else:
- sensitive_config["password"] = snowflake_config["password"]
-
- integration = await Integration.objects.acreate(
- team_id=ateam.pk,
- kind=Integration.IntegrationKind.SNOWFLAKE,
- integration_id="prod-snowflake",
- config={
- "name": "prod-snowflake",
- "account": snowflake_config["account"],
- "user": snowflake_config["user"],
- "authentication_type": snowflake_config["authentication_type"],
- },
- sensitive_config=sensitive_config,
- )
-
- table_name = f"test_integration_activity_table_{ateam.pk}"
- min_ingested_timestamp = dt.datetime.now(dt.UTC).replace(tzinfo=None)
-
- await _run_activity(
- activity_environment=activity_environment,
- snowflake_cursor=snowflake_cursor,
- clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
- team=ateam,
- data_interval_start=data_interval_start,
- data_interval_end=data_interval_end,
- table_name=table_name,
- batch_export_model=BatchExportModel(name="events", schema=None),
- integration_id=integration.id,
- min_ingested_timestamp=min_ingested_timestamp,
- )
-
-
async def test_insert_into_snowflake_activity_merges_persons_data_in_follow_up_runs(
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
generate_test_data,
data_interval_start,
data_interval_end,
@@ -276,7 +215,7 @@ async def test_insert_into_snowflake_activity_merges_persons_data_in_follow_up_r
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -312,7 +251,7 @@ async def test_insert_into_snowflake_activity_merges_persons_data_in_follow_up_r
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -326,7 +265,7 @@ async def test_insert_into_snowflake_activity_merges_sessions_data_in_follow_up_
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
generate_test_data,
data_interval_start,
data_interval_end,
@@ -346,7 +285,7 @@ async def test_insert_into_snowflake_activity_merges_sessions_data_in_follow_up_
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -383,7 +322,7 @@ async def test_insert_into_snowflake_activity_merges_sessions_data_in_follow_up_
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=new_data_interval_start,
data_interval_end=new_data_interval_end,
@@ -409,7 +348,7 @@ async def test_insert_into_snowflake_activity_removes_internal_stage_files(
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
generate_test_data,
data_interval_start,
data_interval_end,
@@ -437,7 +376,7 @@ async def test_insert_into_snowflake_activity_removes_internal_stage_files(
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -473,7 +412,7 @@ async def test_insert_into_snowflake_activity_removes_internal_stage_files(
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -494,7 +433,7 @@ async def test_insert_into_snowflake_activity_heartbeats(
ateam,
snowflake_batch_export,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
activity_environment,
):
"""Test that the insert_into_snowflake_activity_from_stage activity sends heartbeats.
@@ -540,7 +479,7 @@ async def test_insert_into_snowflake_activity_heartbeats(
data_interval_start=data_interval_start.isoformat(),
data_interval_end=data_interval_end.isoformat(),
batch_export_id=str(uuid.uuid4()),
- **snowflake_config,
+ **snowflake_activity_inputs,
)
with override_settings(BATCH_EXPORT_SNOWFLAKE_UPLOAD_CHUNK_SIZE_BYTES=0):
@@ -584,7 +523,7 @@ async def test_insert_into_snowflake_activity_handles_person_schema_changes(
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
generate_test_data,
data_interval_start,
data_interval_end,
@@ -608,7 +547,7 @@ async def test_insert_into_snowflake_activity_handles_person_schema_changes(
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -649,7 +588,7 @@ async def test_insert_into_snowflake_activity_handles_person_schema_changes(
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -664,7 +603,7 @@ async def test_insert_into_snowflake_activity_from_stage_handles_datetime_to_int
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
generate_test_data,
data_interval_start,
data_interval_end,
@@ -693,7 +632,7 @@ async def test_insert_into_snowflake_activity_from_stage_handles_datetime_to_int
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -710,7 +649,7 @@ async def test_insert_into_snowflake_activity_from_stage_handles_datetime_to_int
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -731,7 +670,7 @@ async def test_insert_into_snowflake_activity_handles_uppercased_columns(
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
generate_test_data,
data_interval_start,
data_interval_end,
@@ -755,7 +694,7 @@ async def test_insert_into_snowflake_activity_handles_uppercased_columns(
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -781,7 +720,7 @@ async def test_insert_into_snowflake_activity_handles_uppercased_columns(
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -798,7 +737,7 @@ async def test_insert_into_snowflake_activity_handles_extra_columns_in_destinati
clickhouse_client,
activity_environment,
snowflake_cursor,
- snowflake_config,
+ snowflake_activity_inputs,
generate_test_data,
data_interval_start,
data_interval_end,
@@ -819,7 +758,7 @@ async def test_insert_into_snowflake_activity_handles_extra_columns_in_destinati
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
@@ -836,7 +775,7 @@ async def test_insert_into_snowflake_activity_handles_extra_columns_in_destinati
activity_environment=activity_environment,
snowflake_cursor=snowflake_cursor,
clickhouse_client=clickhouse_client,
- snowflake_config=snowflake_config,
+ snowflake_activity_inputs=snowflake_activity_inputs,
team=ateam,
data_interval_start=data_interval_start,
data_interval_end=data_interval_end,
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py
index 4d1e7d50a33a..cdc6c58697b0 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py
@@ -35,7 +35,7 @@ pytestmark = [
@pytest_asyncio.fixture
-async def snowflake_client(snowflake_config, database, schema):
+async def snowflake_client(snowflake_export_config, snowflake_integration_credentials, database, schema):
"""Create a SnowflakeClient with a test database and schema set up and cleaned up after tests."""
inputs = SnowflakeInsertInputs(
@@ -45,10 +45,12 @@ async def snowflake_client(snowflake_config, database, schema):
).isoformat(), # not important for this test
data_interval_end=(dt.datetime.now(dt.UTC)).isoformat(), # not important for this test
table_name="test_table", # not important for this test
- **snowflake_config,
+ **snowflake_export_config,
)
- async with SnowflakeClient.from_inputs(inputs).connect(use_namespace=False) as client:
+ async with SnowflakeClient.from_integration(snowflake_integration_credentials, inputs).connect(
+ use_namespace=False
+ ) as client:
# Set up: Create database and schema
await client.execute_async_query(f'CREATE DATABASE IF NOT EXISTS "{database}"', fetch_results=False)
await client.execute_async_query(f'CREATE SCHEMA IF NOT EXISTS "{database}"."{schema}"', fetch_results=False)
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py
index b2c59509b911..9ab35baccb4b 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py
@@ -61,6 +61,7 @@ async def _run_workflow(
batch_export_id=str(batch_export_id),
data_interval_end=data_interval_end.isoformat(),
interval=interval,
+ integration_id=snowflake_batch_export.destination.integration_id,
**snowflake_batch_export.destination.config,
)
@@ -374,6 +375,7 @@ async def test_snowflake_export_workflow_handles_cancellation_mocked(ateam, snow
team_id=ateam.pk,
batch_export_id=str(snowflake_batch_export.id),
data_interval_end=data_interval_end.isoformat(),
+ integration_id=snowflake_batch_export.destination.integration_id,
**snowflake_batch_export.destination.config,
)
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow_e2e.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow_e2e.py
index b69c3846ba8c..ef7010f24490 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow_e2e.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow_e2e.py
@@ -72,6 +72,7 @@ async def _run_workflow(
batch_export_schema=batch_export_schema,
batch_export_model=batch_export_model,
backfill_details=backfill_details,
+ integration_id=snowflake_batch_export.destination.integration_id,
**snowflake_batch_export.destination.config,
)
@@ -317,6 +318,7 @@ async def test_snowflake_export_workflow_handles_cancellation(
batch_export_id=str(snowflake_batch_export.id),
data_interval_end=data_interval_end.isoformat(),
interval=interval,
+ integration_id=snowflake_batch_export.destination.integration_id,
**snowflake_batch_export.destination.config,
)