:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(ducklake): use team config for import partition detection (#57967)
Eric Duong599a9c6b2e08
diff --git a/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.py b/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.pyindex 838ae8b627ae..25c47eb36d7f 100644--- a/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.py+++ b/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.py@@ -204,7 +204,9 @@ async def prepare_data_imports_ducklake_metadata_activity(source_table_uri = f"{settings.BUCKET_URL}/{schema.folder_path()}/{normalized_name}"# Get partition column from Delta metadata (source of truth)- partition_column = _detect_data_imports_partition_column(source_table_uri)+ partition_column = await database_sync_to_async(_detect_data_imports_partition_column)(+ source_table_uri, team_id=inputs.team_id+ )staging_uri: str | None = Noneif not is_dev_mode():@@ -333,17 +335,17 @@ def cleanup_data_imports_staging_activity(inputs: DuckLakeDataImportsStagingClea)-def _detect_data_imports_partition_column(table_uri: str) -> str | None:+def _detect_data_imports_partition_column(table_uri: str, *, team_id: int) -> str | None:"""Detect partition column from Delta metadata (source of truth)."""if not table_uri:return None- partition_columns = _fetch_delta_partition_columns(table_uri)+ partition_columns = _fetch_delta_partition_columns(table_uri, team_id=team_id)return partition_columns[0] if partition_columns else None-def _fetch_delta_partition_columns(table_uri: str) -> list[str]:+def _fetch_delta_partition_columns(table_uri: str, *, team_id: int) -> list[str]:"""Fetch partition columns from Delta table metadata."""- options = get_deltalake_storage_options()+ options = get_deltalake_storage_options(team_id=team_id)try:delta_table = deltalake.DeltaTable(table_uri=table_uri, storage_options=options)except Exception as exc:diff --git a/posthog/temporal/tests/ducklake/test_ducklake_copy_data_imports_workflow.py b/posthog/temporal/tests/ducklake/test_ducklake_copy_data_imports_workflow.pyindex ac95a4a5202d..2782f762b211 100644--- a/posthog/temporal/tests/ducklake/test_ducklake_copy_data_imports_workflow.py+++ b/posthog/temporal/tests/ducklake/test_ducklake_copy_data_imports_workflow.py@@ -88,7 +88,7 @@ async def test_ducklake_copy_data_imports_gate_respects_feature_flag(monkeypatch@pytest.mark.django_dbasync def test_prepare_data_imports_ducklake_metadata_activity_basic(ateam, monkeypatch):# Mock Delta partition detection since we can't read actual Delta metadata in tests- monkeypatch.setattr(ducklake_module, "_fetch_delta_partition_columns", lambda table_uri: ["created_at"])+ monkeypatch.setattr(ducklake_module, "_fetch_delta_partition_columns", lambda table_uri, *, team_id: ["created_at"])credential = await database_sync_to_async(DataWarehouseCredential.objects.create)(team=ateam, access_key="test_key", access_secret="test_secret"@@ -143,7 +143,7 @@ async def test_prepare_data_imports_ducklake_metadata_activity_basic(ateam, monk@pytest.mark.django_dbasync def test_prepare_data_imports_ducklake_metadata_activity_no_partition(ateam, monkeypatch):# Mock Delta partition detection - returns empty list when no partitions- monkeypatch.setattr(ducklake_module, "_fetch_delta_partition_columns", lambda table_uri: [])+ monkeypatch.setattr(ducklake_module, "_fetch_delta_partition_columns", lambda table_uri, *, team_id: [])credential = await database_sync_to_async(DataWarehouseCredential.objects.create)(team=ateam, access_key="test_key", access_secret="test_secret"@@ -189,7 +189,7 @@ async def test_prepare_data_imports_ducklake_metadata_activity_no_partition(atea@pytest.mark.asyncio@pytest.mark.django_dbasync def test_prepare_data_imports_ducklake_metadata_activity_with_prefix(ateam, monkeypatch):- monkeypatch.setattr(ducklake_module, "_fetch_delta_partition_columns", lambda table_uri: [])+ monkeypatch.setattr(ducklake_module, "_fetch_delta_partition_columns", lambda table_uri, *, team_id: [])credential = await database_sync_to_async(DataWarehouseCredential.objects.create)(team=ateam, access_key="test_key", access_secret="test_secret"