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(ducklake): return frozen dataclasses instead of tuples (#76134)

Arno Hillen40bfda161d88
diff --git a/posthog/dags/events_backfill_to_duckling.py b/posthog/dags/events_backfill_to_duckling.py
index 03f84c5e5170..70a926f51f48 100644
--- a/posthog/dags/events_backfill_to_duckling.py
+++ b/posthog/dags/events_backfill_to_duckling.py
@@ -231,10 +231,10 @@ def _resolve_table_names(team_id: int) -> tuple[str, str]:
org-scoped duckling don't merge into the shared `posthog.events` / `posthog.persons`.
A team without a row (legacy single-team ducklings) keeps the shared table names.
"""
- events_table, persons_table = resolve_events_persons_tables(team_id)
- _validate_identifier(events_table)
- _validate_identifier(persons_table)
- return events_table, persons_table
+ tables = resolve_events_persons_tables(team_id)
+ _validate_identifier(tables.events_table)
+ _validate_identifier(tables.persons_table)
+ return tables.events_table, tables.persons_table
def _resolve_duckling_target(team_id: int) -> DucklingTarget:
diff --git a/posthog/dags/test_events_backfill_to_duckling.py b/posthog/dags/test_events_backfill_to_duckling.py
index c256552a0e1f..e179373ab08b 100644
--- a/posthog/dags/test_events_backfill_to_duckling.py
+++ b/posthog/dags/test_events_backfill_to_duckling.py
@@ -65,6 +65,7 @@ from products.data_warehouse.backend.facade.backfill_status import BackfillOutco
from products.managed_warehouse.backend.facade.api import EARLIEST_BACKFILL_DATE, NO_HISTORY_SENTINEL
from products.managed_warehouse.backend.facade.client import ServiceCredential, ServiceCredentialUnavailable
from products.managed_warehouse.backend.facade.contracts import (
+ DucklingTables,
ManagedWarehouseTableNames,
ManagedWarehouseTeamMembership,
ServiceCredentialConnect,
@@ -179,14 +180,14 @@ class TestResolveTableNames:
def test_passes_through_resolved_names(self):
with patch(
"posthog.dags.events_backfill_to_duckling.resolve_events_persons_tables",
- return_value=("events_alpha", "persons_alpha"),
+ return_value=DucklingTables(events_table="events_alpha", persons_table="persons_alpha"),
):
assert _resolve_table_names(1) == ("events_alpha", "persons_alpha")
def test_unsafe_resolved_name_is_rejected(self):
with patch(
"posthog.dags.events_backfill_to_duckling.resolve_events_persons_tables",
- return_value=("events_a-b; DROP", "persons"),
+ return_value=DucklingTables(events_table="events_a-b; DROP", persons_table="persons"),
):
with pytest.raises(ValueError):
_resolve_table_names(1)
diff --git a/products/data_warehouse/backend/clickhouse_helpers.py b/products/data_warehouse/backend/clickhouse_helpers.py
index 6246ad954033..6e1ee982df03 100644
--- a/products/data_warehouse/backend/clickhouse_helpers.py
+++ b/products/data_warehouse/backend/clickhouse_helpers.py
@@ -193,16 +193,16 @@ def reconcile_clickhouse_schemas(
update_fields = ["sync_type_config", "updated_at"]
available_names = extract_available_column_names(schema_metadata)
- pruned_enabled_columns, removed_columns = prune_enabled_columns(matched.enabled_columns, available_names)
- if removed_columns:
+ pruned = prune_enabled_columns(matched.enabled_columns, available_names)
+ if pruned.removed:
log.info(
"clickhouse.reconcile_schemas.pruned_enabled_columns",
source_id=str(source.id),
schema_id=str(matched.id),
schema_name=matched.name,
- removed_columns=removed_columns,
+ removed_columns=pruned.removed,
)
- matched.enabled_columns = pruned_enabled_columns
+ matched.enabled_columns = pruned.kept
update_fields.append("enabled_columns")
matched.save(update_fields=update_fields)
diff --git a/products/data_warehouse/backend/mysql_helpers.py b/products/data_warehouse/backend/mysql_helpers.py
index d9fe69432e0e..d8f7877bd0ef 100644
--- a/products/data_warehouse/backend/mysql_helpers.py
+++ b/products/data_warehouse/backend/mysql_helpers.py
@@ -195,16 +195,16 @@ def reconcile_mysql_schemas(
# Drop dead columns so next sync doesn't emit `SELECT … missing_col`.
available_names = extract_available_column_names(schema_metadata)
- pruned_enabled_columns, removed_columns = prune_enabled_columns(matched.enabled_columns, available_names)
- if removed_columns:
+ pruned = prune_enabled_columns(matched.enabled_columns, available_names)
+ if pruned.removed:
log.info(
"mysql.reconcile_schemas.pruned_enabled_columns",
source_id=str(source.id),
schema_id=str(matched.id),
schema_name=matched.name,
- removed_columns=removed_columns,
+ removed_columns=pruned.removed,
)
- matched.enabled_columns = pruned_enabled_columns
+ matched.enabled_columns = pruned.kept
update_fields.append("enabled_columns")
matched.save(update_fields=update_fields)
diff --git a/products/data_warehouse/backend/postgres_helpers.py b/products/data_warehouse/backend/postgres_helpers.py
index 410b387fae0f..552437f3b0e9 100644
--- a/products/data_warehouse/backend/postgres_helpers.py
+++ b/products/data_warehouse/backend/postgres_helpers.py
@@ -229,16 +229,16 @@ def reconcile_postgres_schemas(
# Drop dead columns so next sync doesn't emit `SELECT … missing_col`.
available_names = extract_available_column_names(schema_metadata)
- pruned_enabled_columns, removed_columns = prune_enabled_columns(matched.enabled_columns, available_names)
- if removed_columns:
+ pruned = prune_enabled_columns(matched.enabled_columns, available_names)
+ if pruned.removed:
log.info(
"postgres.reconcile_schemas.pruned_enabled_columns",
source_id=str(source.id),
schema_id=str(matched.id),
schema_name=matched.name,
- removed_columns=removed_columns,
+ removed_columns=pruned.removed,
)
- matched.enabled_columns = pruned_enabled_columns
+ matched.enabled_columns = pruned.kept
update_fields.append("enabled_columns")
matched.save(update_fields=update_fields)
diff --git a/products/data_warehouse/backend/redshift_helpers.py b/products/data_warehouse/backend/redshift_helpers.py
index 9c62afe61506..7efabcaa6a37 100644
--- a/products/data_warehouse/backend/redshift_helpers.py
+++ b/products/data_warehouse/backend/redshift_helpers.py
@@ -242,16 +242,16 @@ def reconcile_redshift_schemas(
# Drop dead columns so next sync doesn't emit `SELECT … missing_col`.
available_names = extract_available_column_names(schema_metadata)
- pruned_enabled_columns, removed_columns = prune_enabled_columns(matched.enabled_columns, available_names)
- if removed_columns:
+ pruned = prune_enabled_columns(matched.enabled_columns, available_names)
+ if pruned.removed:
log.info(
"redshift.reconcile_schemas.pruned_enabled_columns",
source_id=str(source.id),
schema_id=str(matched.id),
schema_name=matched.name,
- removed_columns=removed_columns,
+ removed_columns=pruned.removed,
)
- matched.enabled_columns = pruned_enabled_columns
+ matched.enabled_columns = pruned.kept
update_fields.append("enabled_columns")
matched.save(update_fields=update_fields)
diff --git a/products/data_warehouse/backend/snowflake_helpers.py b/products/data_warehouse/backend/snowflake_helpers.py
index f8030f1fcd9e..46d0c6cc8d0a 100644
--- a/products/data_warehouse/backend/snowflake_helpers.py
+++ b/products/data_warehouse/backend/snowflake_helpers.py
@@ -240,16 +240,16 @@ def reconcile_snowflake_schemas(
# Drop dead columns so next sync doesn't emit `SELECT … missing_col`.
available_names = extract_available_column_names(schema_metadata)
- pruned_enabled_columns, removed_columns = prune_enabled_columns(matched.enabled_columns, available_names)
- if removed_columns:
+ pruned = prune_enabled_columns(matched.enabled_columns, available_names)
+ if pruned.removed:
log.info(
"snowflake.reconcile_schemas.pruned_enabled_columns",
source_id=str(source.id),
schema_id=str(matched.id),
schema_name=matched.name,
- removed_columns=removed_columns,
+ removed_columns=pruned.removed,
)
- matched.enabled_columns = pruned_enabled_columns
+ matched.enabled_columns = pruned.kept
update_fields.append("enabled_columns")
matched.save(update_fields=update_fields)
diff --git a/products/managed_warehouse/backend/facade/contracts.py b/products/managed_warehouse/backend/facade/contracts.py
index 497c3b74c59d..a783517c4f3d 100644
--- a/products/managed_warehouse/backend/facade/contracts.py
+++ b/products/managed_warehouse/backend/facade/contracts.py
@@ -30,6 +30,7 @@ __all__ = [
"DuckLakeQueryResult",
"DuckLakeS3Secret",
"DuckLakeTableResult",
+ "DucklingTables",
"ManagedWarehouseBackfillState",
"ManagedWarehouseProvisionStatus",
"ManagedWarehouseSourceJobRecord",
@@ -147,6 +148,14 @@ class DuckgresStoredServerConfig:
bucket: DuckgresStoredBucketConfig | None
+@frozen
+class DucklingTables:
+ """The per-team events/persons duckling table names the backfill writes to."""
+
+ events_table: str
+ persons_table: str
+
+
@dataclass(frozen=True, kw_only=True)
class ManagedWarehouseTableNames:
"""Resolved per-team table and schema names owned by the control plane."""
diff --git a/products/managed_warehouse/backend/facade/team_state.py b/products/managed_warehouse/backend/facade/team_state.py
index a14b6dcb8a11..de6fade03997 100644
--- a/products/managed_warehouse/backend/facade/team_state.py
+++ b/products/managed_warehouse/backend/facade/team_state.py
@@ -3,6 +3,7 @@
from __future__ import annotations
from products.managed_warehouse.backend.facade.contracts import (
+ DucklingTables,
ManagedWarehouseBackfillState,
ManagedWarehouseTeamMembership,
)
@@ -18,7 +19,7 @@ __all__ = [
]
-def resolve_events_persons_tables(team_id: int) -> tuple[str, str]:
+def resolve_events_persons_tables(team_id: int) -> DucklingTables:
from products.managed_warehouse.backend import team_state
return team_state.resolve_events_persons_tables(team_id)
diff --git a/products/managed_warehouse/backend/storage.py b/products/managed_warehouse/backend/storage.py
index 274f0482a4f3..d668efac6b57 100644
--- a/products/managed_warehouse/backend/storage.py
+++ b/products/managed_warehouse/backend/storage.py
@@ -25,6 +25,8 @@ from urllib.parse import urlparse
import psycopg
+from posthog.dataclasses import frozen
+
from products.managed_warehouse.backend.common import (
_get_org_id_for_team,
default_bucket_region,
@@ -50,7 +52,14 @@ def _get_django_settings():
return None
-def _get_boto3_credentials() -> tuple[str, str, str | None]:
+@frozen
+class AwsCredentials:
+ access_key: str
+ secret_key: str = dataclasses.field(repr=False)
+ session_token: str | None = dataclasses.field(default=None, repr=False)
+
+
+def _get_boto3_credentials() -> AwsCredentials:
"""Fetch AWS credentials via boto3.
This is a workaround for DuckDB's CREDENTIAL_CHAIN not supporting
@@ -60,8 +69,7 @@ def _get_boto3_credentials() -> tuple[str, str, str | None]:
See: https://github.com/duckdb/duckdb-aws/issues/31
Returns:
- Tuple of (access_key, secret_key, session_token).
- session_token may be None for static credentials.
+ AwsCredentials; session_token may be None for static credentials.
"""
import boto3
@@ -72,10 +80,10 @@ def _get_boto3_credentials() -> tuple[str, str, str | None]:
frozen = credentials.get_frozen_credentials()
if frozen.access_key is None or frozen.secret_key is None:
raise RuntimeError("AWS credentials missing access_key or secret_key")
- return frozen.access_key, frozen.secret_key, frozen.token
+ return AwsCredentials(access_key=frozen.access_key, secret_key=frozen.secret_key, session_token=frozen.token)
-def _get_cross_account_credentials(role_arn: str, external_id: str | None = None) -> tuple[str, str, str]:
+def _get_cross_account_credentials(role_arn: str, external_id: str | None = None) -> AwsCredentials:
"""Assume a cross-account IAM role and return temporary credentials.
Args:
@@ -83,7 +91,7 @@ def _get_cross_account_credentials(role_arn: str, external_id: str | None = None
external_id: Optional external ID for the role assumption (recommended for security)
Returns:
- Tuple of (access_key, secret_key, session_token)
+ AwsCredentials with a session token from the assumed role.
"""
import boto3
@@ -98,7 +106,9 @@ def _get_cross_account_credentials(role_arn: str, external_id: str | None = None
response = sts.assume_role(**assume_role_kwargs)
creds = response["Credentials"]
- return creds["AccessKeyId"], creds["SecretAccessKey"], creds["SessionToken"]
+ return AwsCredentials(
+ access_key=creds["AccessKeyId"], secret_key=creds["SecretAccessKey"], session_token=creds["SessionToken"]
+ )
def normalize_endpoint(endpoint: str) -> tuple[str, bool]:
@@ -224,14 +234,14 @@ class DuckLakeStorageConfig:
# Workaround: DuckDB's CREDENTIAL_CHAIN doesn't support IRSA (Web Identity Token).
# Fetch credentials via boto3 which properly supports IRSA.
# See: https://github.com/duckdb/duckdb-aws/issues/31
- access_key, secret_key, session_token = _get_boto3_credentials()
+ creds = _get_boto3_credentials()
secret_parts = [
"TYPE S3",
- f"KEY_ID '{ducklake_escape(access_key)}'",
- f"SECRET '{ducklake_escape(secret_key)}'",
+ f"KEY_ID '{ducklake_escape(creds.access_key)}'",
+ f"SECRET '{ducklake_escape(creds.secret_key)}'",
]
- if session_token:
- secret_parts.append(f"SESSION_TOKEN '{ducklake_escape(session_token)}'")
+ if creds.session_token:
+ secret_parts.append(f"SESSION_TOKEN '{ducklake_escape(creds.session_token)}'")
if self.region:
secret_parts.append(f"REGION '{ducklake_escape(self.region)}'")
return f"CREATE OR REPLACE SECRET {secret_name} ({', '.join(secret_parts)})"
@@ -254,9 +264,8 @@ class DuckLakeStorageConfig:
self,
secret_name: str,
scope: str,
- access_key: str,
- secret_key: str,
- session_token: str | None = None,
+ *,
+ credentials: AwsCredentials,
region: str | None = None,
) -> str:
"""Generate a scoped DuckDB CREATE SECRET statement.
@@ -267,9 +276,7 @@ class DuckLakeStorageConfig:
Args:
secret_name: Unique name for this secret
scope: S3 bucket scope (e.g., 's3://bucket-name')
- access_key: AWS access key
- secret_key: AWS secret key
- session_token: Optional session token for temporary credentials
+ credentials: AWS credentials for the scoped secret
region: AWS region (defaults to self.region)
Returns:
@@ -281,11 +288,11 @@ class DuckLakeStorageConfig:
secret_parts = [
"TYPE S3",
- f"KEY_ID '{ducklake_escape(access_key)}'",
- f"SECRET '{ducklake_escape(secret_key)}'",
+ f"KEY_ID '{ducklake_escape(credentials.access_key)}'",
+ f"SECRET '{ducklake_escape(credentials.secret_key)}'",
]
- if session_token:
- secret_parts.append(f"SESSION_TOKEN '{ducklake_escape(session_token)}'")
+ if credentials.session_token:
+ secret_parts.append(f"SESSION_TOKEN '{ducklake_escape(credentials.session_token)}'")
secret_parts.append(f"REGION '{ducklake_escape(effective_region)}'")
secret_parts.append(f"SCOPE '{ducklake_escape(scope)}'")
@@ -420,16 +427,14 @@ def configure_cross_account_connection(
# Set up destination credentials (via cross-account role assumption)
if destinations:
for i, dest in enumerate(destinations):
- access_key, secret_key, session_token = _get_cross_account_credentials(
+ creds = _get_cross_account_credentials(
dest.role_arn,
external_id=dest.external_id,
)
secret_sql = source_storage_config.to_duckdb_scoped_secret_sql(
secret_name=f"ducklake_s3_dest_{i}",
scope=f"s3://{dest.bucket_name}",
- access_key=access_key,
- secret_key=secret_key,
- session_token=session_token,
+ credentials=creds,
region=dest.region,
)
conn.execute(secret_sql)
diff --git a/products/managed_warehouse/backend/team_state.py b/products/managed_warehouse/backend/team_state.py
index 5adba5025715..a8ec8524e397 100644
--- a/products/managed_warehouse/backend/team_state.py
+++ b/products/managed_warehouse/backend/team_state.py
@@ -18,6 +18,7 @@ from products.managed_warehouse.backend import cp_teams
from products.managed_warehouse.backend.common import _get_org_id_for_team, validate_duckgres_identifier
from products.managed_warehouse.backend.facade.contracts import (
CPUnavailableError,
+ DucklingTables,
ManagedWarehouseBackfillState,
ManagedWarehouseTableNames,
ManagedWarehouseTeamMembership,
@@ -58,8 +59,8 @@ def _to_membership(row: cp_teams.CPTeam) -> ManagedWarehouseTeamMembership:
# --- events/persons table names (Dagster duckling backfill) -----------------------
-def resolve_events_persons_tables(team_id: int) -> tuple[str, str]:
- """The per-team (events, persons) duckling table names the backfill writes to.
+def resolve_events_persons_tables(team_id: int) -> DucklingTables:
+ """The per-team events/persons duckling table names the backfill writes to.
Failure posture: raises :class:`CPUnavailableError` when the control plane can't
answer and the cache is cold — the backfill run fails and retries rather than
@@ -68,11 +69,11 @@ def resolve_events_persons_tables(team_id: int) -> tuple[str, str]:
row = _get_cp_row(team_id)
if row is None:
# Legacy single-team ducklings without a team row share the base tables.
- return "events", "persons"
+ return DucklingTables(events_table="events", persons_table="persons")
events_table, persons_table = row.resolved_events_table, row.resolved_persons_table
validate_duckgres_identifier(events_table)
validate_duckgres_identifier(persons_table)
- return events_table, persons_table
+ return DucklingTables(events_table=events_table, persons_table=persons_table)
# --- data-imports schema (v3 sink hot path) ---------------------------------------
diff --git a/products/managed_warehouse/backend/tests/test_storage.py b/products/managed_warehouse/backend/tests/test_storage.py
index bfcf03371d9b..85cc0960b4c6 100644
--- a/products/managed_warehouse/backend/tests/test_storage.py
+++ b/products/managed_warehouse/backend/tests/test_storage.py
@@ -6,6 +6,7 @@ from parameterized import parameterized
from products.managed_warehouse.backend.storage import (
_DELTA_LOG_VERSION_RE,
+ AwsCredentials,
DuckLakeStorageConfig,
_collect_delta_log_keys,
normalize_endpoint,
@@ -166,7 +167,9 @@ class TestDuckLakeStorageConfigProduction:
monkeypatch.setattr("products.managed_warehouse.backend.storage._get_django_settings", lambda: mock_settings)
monkeypatch.setattr(
"products.managed_warehouse.backend.storage._get_boto3_credentials",
- lambda: ("ASIAACCESSKEY", "secretkey123", "sessiontoken456"),
+ lambda: AwsCredentials(
+ access_key="ASIAACCESSKEY", secret_key="secretkey123", session_token="sessiontoken456"
+ ),
)
config = DuckLakeStorageConfig.from_runtime()
@@ -194,7 +197,7 @@ class TestDuckLakeStorageConfigProduction:
monkeypatch.setattr("products.managed_warehouse.backend.storage._get_django_settings", lambda: mock_settings)
monkeypatch.setattr(
"products.managed_warehouse.backend.storage._get_boto3_credentials",
- lambda: ("AKIAACCESSKEY", "secretkey789", None),
+ lambda: AwsCredentials(access_key="AKIAACCESSKEY", secret_key="secretkey789"),
)
config = DuckLakeStorageConfig.from_runtime()
diff --git a/products/managed_warehouse/backend/tests/test_team_state.py b/products/managed_warehouse/backend/tests/test_team_state.py
index 907cb4914cda..b06e62180910 100644
--- a/products/managed_warehouse/backend/tests/test_team_state.py
+++ b/products/managed_warehouse/backend/tests/test_team_state.py
@@ -93,15 +93,19 @@ class TestEventsPersonsTables:
@parameterized.expand(
[
# Derive rule and pin precedence as served through the accessor.
- ("derived", {}, ("events_cp_schema", "persons_cp_schema")),
+ (
+ "derived",
+ {},
+ team_state.DucklingTables(events_table="events_cp_schema", persons_table="persons_cp_schema"),
+ ),
(
"grandfathered_shared_pins",
{"events_table_name": "events", "persons_table_name": "persons"},
- ("events", "persons"),
+ team_state.DucklingTables(events_table="events", persons_table="persons"),
),
]
)
- def test_resolves_from_cp_row(self, _name: str, overrides: dict, expected: tuple[str, str]) -> None:
+ def test_resolves_from_cp_row(self, _name: str, overrides: dict, expected: team_state.DucklingTables) -> None:
org, team = _team()
with _patch_org_rows([_cp_row(team, "cp_schema", **overrides)]):
assert team_state.resolve_events_persons_tables(team.id) == expected
@@ -109,7 +113,9 @@ class TestEventsPersonsTables:
def test_without_cp_row_falls_back_to_shared_tables(self) -> None:
org, team = _team()
with _patch_org_rows([]):
- assert team_state.resolve_events_persons_tables(team.id) == ("events", "persons")
+ assert team_state.resolve_events_persons_tables(team.id) == team_state.DucklingTables(
+ events_table="events", persons_table="persons"
+ )
def test_raises_when_cp_unreachable_and_cache_cold(self) -> None:
org, team = _team()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/base.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/base.py
index 536790b91f27..9f53fca20b3f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/base.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/base.py
@@ -200,17 +200,17 @@ def reconcile_source_schema_metadata(
existing_config["schema_metadata"] = new_metadata
available_names = extract_available_column_names(new_metadata)
- pruned_enabled_columns, removed_columns = prune_enabled_columns(row.enabled_columns, available_names)
+ pruned = prune_enabled_columns(row.enabled_columns, available_names)
update_fields = ["sync_type_config", "updated_at"]
- if removed_columns:
+ if pruned.removed:
log.info(
"sql_source.reconcile_schema_metadata.pruned_enabled_columns",
source_id=str(source.id),
schema_id=str(row.id),
schema_name=row.name,
- removed_columns=removed_columns,
+ removed_columns=pruned.removed,
)
- row.enabled_columns = pruned_enabled_columns
+ row.enabled_columns = pruned.kept
update_fields.append("enabled_columns")
row.sync_type_config = existing_config
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/projection.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/projection.py
index 7974ef3fd972..2ffdfdd14048 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/projection.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/projection.py
@@ -15,6 +15,8 @@ from typing import TypeVar
import structlog
+from posthog.dataclasses import frozen
+
from products.warehouse_sources.backend.temporal.data_imports.naming_convention import NamingConvention
from products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.identifiers import IdentifierQuoter
from products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.types import Column, Table
@@ -169,13 +171,19 @@ def project_arrow_columns(
return Table(name=table.name, columns=projected, parents=table.parents, alias=table.alias, type=table.type)
+@frozen
+class PrunedColumns:
+ kept: list[str] | None
+ removed: list[str]
+
+
def prune_enabled_columns(
enabled_columns: list[str] | None,
available_column_names: set[str],
-) -> tuple[list[str] | None, list[str]]:
- """Drop `enabled_columns` entries missing from the source. Returns `(kept, removed)`."""
+) -> PrunedColumns:
+ """Drop `enabled_columns` entries missing from the source."""
if enabled_columns is None:
- return None, []
+ return PrunedColumns(kept=None, removed=[])
kept: list[str] = []
removed: list[str] = []
for column in enabled_columns:
@@ -183,4 +191,4 @@ def prune_enabled_columns(
kept.append(column)
else:
removed.append(column)
- return kept, removed
+ return PrunedColumns(kept=kept, removed=removed)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_projection.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_projection.py
index bf5d4975f43b..b80bbd66b4e5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_projection.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_projection.py
@@ -15,6 +15,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sql
InvalidIdentifierError,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.projection import (
+ PrunedColumns,
compute_projected_columns,
filter_columns_by_enabled_columns,
filter_dwh_columns_by_enabled_columns,
@@ -205,24 +206,24 @@ class TestFilterDwhColumnsByEnabledColumns:
class TestPruneEnabledColumns:
def test_none_passes_through(self) -> None:
- assert prune_enabled_columns(None, {"id", "email"}) == (None, [])
+ assert prune_enabled_columns(None, {"id", "email"}) == PrunedColumns(kept=None, removed=[])
def test_drops_missing_columns(self) -> None:
- kept, removed = prune_enabled_columns(["id", "email", "ghost"], {"id", "email"})
- assert kept == ["id", "email"]
- assert removed == ["ghost"]
+ pruned = prune_enabled_columns(["id", "email", "ghost"], {"id", "email"})
+ assert pruned.kept == ["id", "email"]
+ assert pruned.removed == ["ghost"]
def test_empty_list_passes_through(self) -> None:
- assert prune_enabled_columns([], {"id", "email"}) == ([], [])
+ assert prune_enabled_columns([], {"id", "email"}) == PrunedColumns(kept=[], removed=[])
def test_all_kept_when_all_present(self) -> None:
- kept, removed = prune_enabled_columns(["id", "email"], {"id", "email", "name"})
- assert kept == ["id", "email"]
- assert removed == []
+ pruned = prune_enabled_columns(["id", "email"], {"id", "email", "name"})
+ assert pruned.kept == ["id", "email"]
+ assert pruned.removed == []
def test_preserves_caller_order(self) -> None:
- kept, _ = prune_enabled_columns(["email", "id", "name"], {"id", "email", "name"})
- assert kept == ["email", "id", "name"]
+ pruned = prune_enabled_columns(["email", "id", "name"], {"id", "email", "name"})
+ assert pruned.kept == ["email", "id", "name"]
class TestProjectArrowColumns: