: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): remove unused cross-account catalog fields (#64057)
James Greenhill3cd858459dd2
diff --git a/posthog/admin/admins/ducklake_catalog_admin.py b/posthog/admin/admins/ducklake_catalog_admin.pyindex e7b88aa7d7df..5b0d67f3a3d7 100644--- a/posthog/admin/admins/ducklake_catalog_admin.py+++ b/posthog/admin/admins/ducklake_catalog_admin.py@@ -13,12 +13,11 @@ class DuckLakeCatalogAdmin(admin.ModelAdmin):"db_database","bucket","bucket_region",- "cross_account_role_arn","created_at","updated_at",)list_filter = ("bucket_region",)- search_fields = ("=team__id", "=organization__id", "db_host", "bucket", "cross_account_role_arn")+ search_fields = ("=team__id", "=organization__id", "db_host", "bucket")readonly_fields = ("id", "created_at", "updated_at")raw_id_fields = ("team", "organization")@@ -41,13 +40,6 @@ class DuckLakeCatalogAdmin(admin.ModelAdmin):"fields": ("bucket", "bucket_region"),},),- (- "Cross-account S3 access",- {- "fields": ("cross_account_role_arn", "cross_account_external_id"),- "description": "Required settings for writing to customer-owned S3 buckets via IAM role assumption",- },- ),("Metadata",{diff --git a/posthog/dags/README_DUCKLINGS.md b/posthog/dags/README_DUCKLINGS.mdindex 4d56f5135a96..639f79a84d8d 100644--- a/posthog/dags/README_DUCKLINGS.md+++ b/posthog/dags/README_DUCKLINGS.md@@ -114,8 +114,8 @@ class DucklingBackfillConfig:- `bucket_region`: AWS region- `db_host`: RDS endpoint- `db_name`: Database name- - `cross_account_role_arn`: IAM role for Dagster to assume- - `cross_account_external_id`: External ID for role assumption++ Ensure the runtime IAM role can read from and write to the configured S3 bucket.2. The discovery sensor will automatically pick up the new team on its next rundiff --git a/posthog/ducklake/models.py b/posthog/ducklake/models.pyindex c388cd6234c1..d44c937ac40f 100644--- a/posthog/ducklake/models.py+++ b/posthog/ducklake/models.py@@ -1,15 +1,10 @@from __future__ import annotations-from typing import TYPE_CHECKING-from django.db import modelsfrom posthog.helpers.encrypted_fields import EncryptedTextFieldfrom posthog.models.utils import CreatedMetaFields, UpdatedMetaFields, UUIDModel-if TYPE_CHECKING:- from posthog.ducklake.storage import CrossAccountDestination-class DuckLakeCatalog(CreatedMetaFields, UpdatedMetaFields, UUIDModel):"""Per-organization DuckLake catalog configuration.@@ -46,16 +41,6 @@ class DuckLakeCatalog(CreatedMetaFields, UpdatedMetaFields, UUIDModel):bucket = models.CharField(max_length=255)bucket_region = models.CharField(max_length=50, default="us-east-1")- # Cross-account S3 access settings (required - for writing to customer-owned buckets)- cross_account_role_arn = models.CharField(- max_length=255,- help_text="ARN of the IAM role to assume for cross-account S3 access",- )- cross_account_external_id = EncryptedTextField(- max_length=500,- help_text="External ID for cross-account role assumption (encrypted)",- )-class Meta:db_table = "posthog_ducklakecatalog"verbose_name = "DuckLake catalog"@@ -74,17 +59,6 @@ class DuckLakeCatalog(CreatedMetaFields, UpdatedMetaFields, UUIDModel):"DUCKLAKE_S3_SECRET_KEY": "",}- def to_cross_account_destination(self) -> CrossAccountDestination:- """Convert to a CrossAccountDestination for cross-account S3 access."""- from posthog.ducklake.storage import CrossAccountDestination-- return CrossAccountDestination(- role_arn=self.cross_account_role_arn,- bucket_name=self.bucket,- external_id=self.cross_account_external_id,- region=self.bucket_region or None,- )-class DuckgresServer(CreatedMetaFields, UpdatedMetaFields, UUIDModel):"""Per-organization duckgres query server connection details.diff --git a/posthog/ducklake/storage.py b/posthog/ducklake/storage.pyindex 58df60a776d8..afb80d885b7f 100644--- a/posthog/ducklake/storage.py+++ b/posthog/ducklake/storage.py@@ -583,8 +583,6 @@ def _collect_delta_log_keys(def stage_delta_table(source_uri: str,catalog_bucket: str,- role_arn: str,- external_id: str | None = None,*,storage_config: DuckLakeStorageConfig | None = None,team_id: int | None = None,@@ -615,14 +613,7 @@ def stage_delta_table(organization_id=organization_id,)- access_key, secret_key, session_token = _get_cross_account_credentials(role_arn, external_id)-- s3 = boto3.client(- "s3",- aws_access_key_id=access_key,- aws_secret_access_key=secret_key,- aws_session_token=session_token,- )+ s3 = boto3.client("s3")log_keys = _collect_delta_log_keys(s3, source_bucket, source_prefix, version)@@ -644,8 +635,6 @@ def stage_delta_table(def cleanup_staged_files(staging_uri: str,- role_arn: str,- external_id: str | None = None,) -> None:"""Delete staged Delta files from the staging bucket."""import boto3@@ -656,14 +645,7 @@ def cleanup_staged_files(if not prefix.endswith("/"):prefix += "/"- access_key, secret_key, session_token = _get_cross_account_credentials(role_arn, external_id)-- s3 = boto3.client(- "s3",- aws_access_key_id=access_key,- aws_secret_access_key=secret_key,- aws_session_token=session_token,- )+ s3 = boto3.client("s3")paginator = s3.get_paginator("list_objects_v2")for page in paginator.paginate(Bucket=bucket, Prefix=prefix):diff --git a/posthog/ducklake/test_storage.py b/posthog/ducklake/test_storage.pyindex ab385b7734cd..f33f41487a08 100644--- a/posthog/ducklake/test_storage.py+++ b/posthog/ducklake/test_storage.py@@ -314,43 +314,6 @@ class TestCrossAccountDestination:assert dest.region is None-class TestDuckLakeCatalogToCrossAccountDestination:- def test_converts_to_cross_account_destination(self):- from unittest.mock import MagicMock-- from posthog.ducklake.models import DuckLakeCatalog-- # Create a mock catalog with the required attributes- catalog = MagicMock(spec=DuckLakeCatalog)- catalog.cross_account_role_arn = "arn:aws:iam::222222222222:role/CustomerRole"- catalog.cross_account_external_id = "external-id-456"- catalog.bucket = "customer-bucket"- catalog.bucket_region = "eu-west-1"-- # Call the real method on the mock- dest = DuckLakeCatalog.to_cross_account_destination(catalog)-- assert dest.role_arn == "arn:aws:iam::222222222222:role/CustomerRole"- assert dest.external_id == "external-id-456"- assert dest.bucket_name == "customer-bucket"- assert dest.region == "eu-west-1"-- def test_none_region_handled(self):- from unittest.mock import MagicMock-- from posthog.ducklake.models import DuckLakeCatalog-- catalog = MagicMock(spec=DuckLakeCatalog)- catalog.cross_account_role_arn = "arn:aws:iam::111:role/Role"- catalog.cross_account_external_id = "ext-id"- catalog.bucket = "bucket"- catalog.bucket_region = "" # Empty string should become None-- dest = DuckLakeCatalog.to_cross_account_destination(catalog)-- assert dest.region is None--def _make_s3_page(keys: list[str]) -> list[dict]:return [{"Contents": [{"Key": k} for k in keys]}]@@ -508,10 +471,6 @@ class TestStageDeltaTable:))monkeypatch.setattr("posthog.ducklake.storage._get_delta_snapshot_files", mock_get_snapshot_files)- monkeypatch.setattr(- "posthog.ducklake.storage._get_cross_account_credentials",- lambda role_arn, external_id=None: ("ak", "sk", "tok"),- )mock_s3 = MagicMock()mock_s3.get_paginator.return_value = _mock_paginator(@@ -532,7 +491,6 @@ class TestStageDeltaTable:result = stage_delta_table(source_uri="s3://customer-bucket/data/table",catalog_bucket="catalog-bucket",- role_arn="arn:aws:iam::123:role/Role",organization_id="org-123",)diff --git a/posthog/migrations/1223_remove_ducklakecatalog_cross_account_fields.py b/posthog/migrations/1223_remove_ducklakecatalog_cross_account_fields.pynew file mode 100644index 000000000000..7917f6206c2a--- /dev/null+++ b/posthog/migrations/1223_remove_ducklakecatalog_cross_account_fields.py@@ -0,0 +1,32 @@+from django.db import migrations+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1222_alter_integration_kind_google_analytics"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.RemoveField(+ model_name="ducklakecatalog",+ name="cross_account_external_id",+ ),+ migrations.RemoveField(+ model_name="ducklakecatalog",+ name="cross_account_role_arn",+ ),+ ],+ database_operations=[+ migrations.RunSQL(+ sql="""+ ALTER TABLE posthog_ducklakecatalog+ ALTER COLUMN cross_account_external_id DROP NOT NULL,+ ALTER COLUMN cross_account_role_arn DROP NOT NULL;+ """,+ reverse_sql=migrations.RunSQL.noop,+ ),+ ],+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex e78e55ae4293..65584c9596fc 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1222_alter_integration_kind_google_analytics+1223_remove_ducklakecatalog_cross_account_fieldsdiff --git a/posthog/tasks/tasks.py b/posthog/tasks/tasks.pyindex 3269b6bf9566..3772ccddcada 100644--- a/posthog/tasks/tasks.py+++ b/posthog/tasks/tasks.py@@ -971,7 +971,7 @@ def background_delete_model_task(import structloglogger = structlog.get_logger(__name__)- logger.setLevel(logging.INFO)+ logging.getLogger(__name__).setLevel(logging.INFO)try:# Parse model namediff --git a/posthog/tasks/usage_report.py b/posthog/tasks/usage_report.pyindex 554be6ce3833..9cde9a6fc470 100644--- a/posthog/tasks/usage_report.py+++ b/posthog/tasks/usage_report.py@@ -62,7 +62,7 @@ from products.warehouse_sources.backend.models.external_data_schema import Exterfrom products.warehouse_sources.backend.models.table import DataWarehouseTablelogger = structlog.get_logger(__name__)-logger.setLevel(logging.INFO)+logging.getLogger(__name__).setLevel(logging.INFO)# AI events dynamically generated from AIEventType TS enum# Changes to the AIEventType enum will impact usage reportingdiff --git a/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.py b/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.pyindex 3f02d6f9d81e..7164c0102ccd 100644--- a/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.py+++ b/posthog/temporal/ducklake/ducklake_copy_data_imports_workflow.py@@ -296,8 +296,6 @@ def _copy_data_imports_via_duckgres(inputs: DuckLakeCopyDataImportsActivityInputstage_delta_table(source_uri=inputs.model.source_table_uri,catalog_bucket=catalog.bucket,- role_arn=catalog.cross_account_role_arn,- external_id=catalog.cross_account_external_id,organization_id=org_id,)@@ -334,8 +332,6 @@ def cleanup_data_imports_staging_activity(inputs: DuckLakeDataImportsStagingCleareturncleanup_staged_files(staging_uri=inputs.staging_uri,- role_arn=catalog.cross_account_role_arn,- external_id=catalog.cross_account_external_id,)diff --git a/posthog/temporal/ducklake/ducklake_copy_data_modeling_workflow.py b/posthog/temporal/ducklake/ducklake_copy_data_modeling_workflow.pyindex 1d50fc03ea27..c9c9a6b97c58 100644--- a/posthog/temporal/ducklake/ducklake_copy_data_modeling_workflow.py+++ b/posthog/temporal/ducklake/ducklake_copy_data_modeling_workflow.py@@ -24,7 +24,6 @@ from posthog.ducklake.storage import (cleanup_staged_files,compute_staging_uri,configure_connection,- configure_cross_account_connection,connect_to_duckgres,ensure_ducklake_bucket_exists,get_deltalake_storage_options,@@ -250,7 +249,7 @@ def verify_ducklake_copy_activity(inputs: DuckLakeCopyActivityInputs) -> list[Du)config = catalog.to_public_config()config["DUCKLAKE_RDS_PASSWORD"] = catalog.db_password- configure_cross_account_connection(conn, destinations=[catalog.to_cross_account_destination()])+ configure_connection(conn)_attach_ducklake_catalog(conn, config, alias=alias)ducklake_table = f"{alias}.{inputs.model.schema_name}.{inputs.model.table_name}"@@ -519,8 +518,6 @@ def _copy_data_modeling_via_duckgres(inputs: DuckLakeCopyActivityInputs, logger)stage_delta_table(source_uri=inputs.model.source_table_uri,catalog_bucket=catalog.bucket,- role_arn=catalog.cross_account_role_arn,- external_id=catalog.cross_account_external_id,organization_id=org_id,)@@ -557,8 +554,6 @@ def cleanup_data_modeling_staging_activity(inputs: DuckLakeDataModelingStagingClreturncleanup_staged_files(staging_uri=inputs.staging_uri,- role_arn=catalog.cross_account_role_arn,- external_id=catalog.cross_account_external_id,)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 bac518329f39..80979cf28c75 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@@ -268,7 +268,7 @@ async def test_prepare_data_imports_ducklake_metadata_activity_empty_schema_ids(def _create_mock_catalog():- """Create a mock DuckLakeCatalog with cross-account settings."""+ """Create a mock DuckLakeCatalog."""mock_catalog = MagicMock()mock_catalog.to_public_config.return_value = {"DUCKLAKE_RDS_HOST": "localhost",@@ -282,12 +282,6 @@ def _create_mock_catalog():"DUCKLAKE_S3_SECRET_KEY": "",}mock_catalog.bucket = "test-bucket"- mock_catalog.cross_account_role_arn = "arn:aws:iam::123456789012:role/test-role"- mock_catalog.cross_account_external_id = "external-id-123"- mock_cross_account_dest = MagicMock()- mock_cross_account_dest.role_arn = "arn:aws:iam::123456789012:role/test-role"- mock_cross_account_dest.bucket_name = "test-bucket"- mock_catalog.to_cross_account_destination.return_value = mock_cross_account_destreturn mock_catalog@@ -477,8 +471,6 @@ def test_copy_data_imports_to_ducklake_activity_via_duckgres(monkeypatch):mock_stage.assert_called_once_with(source_uri="s3://bucket/team_1/customers",catalog_bucket="test-bucket",- role_arn="arn:aws:iam::123456789012:role/test-role",- external_id="external-id-123",organization_id="org-123",)execute_calls = mock_conn.execute.call_args_listdiff --git a/posthog/temporal/tests/ducklake/test_ducklake_copy_data_modeling_workflow.py b/posthog/temporal/tests/ducklake/test_ducklake_copy_data_modeling_workflow.pyindex 0cd9b2af64de..5535c246ec49 100644--- a/posthog/temporal/tests/ducklake/test_ducklake_copy_data_modeling_workflow.py+++ b/posthog/temporal/tests/ducklake/test_ducklake_copy_data_modeling_workflow.py@@ -29,7 +29,7 @@ from products.data_modeling.backend.models.datawarehouse_saved_query import Datadef _create_mock_catalog():- """Create a mock DuckLakeCatalog with cross-account settings."""+ """Create a mock DuckLakeCatalog."""mock_catalog = MagicMock()mock_catalog.to_public_config.return_value = {"DUCKLAKE_RDS_HOST": "localhost",@@ -43,12 +43,6 @@ def _create_mock_catalog():"DUCKLAKE_S3_SECRET_KEY": "",}mock_catalog.bucket = "test-bucket"- mock_catalog.cross_account_role_arn = "arn:aws:iam::123456789012:role/test-role"- mock_catalog.cross_account_external_id = "external-id-123"- mock_cross_account_dest = MagicMock()- mock_cross_account_dest.role_arn = "arn:aws:iam::123456789012:role/test-role"- mock_cross_account_dest.bucket_name = "test-bucket"- mock_catalog.to_cross_account_destination.return_value = mock_cross_account_destreturn mock_catalog@@ -248,8 +242,6 @@ def test_copy_data_modeling_model_to_ducklake_activity_via_duckgres(monkeypatch)mock_stage.assert_called_once_with(source_uri="s3://source/table",catalog_bucket="test-bucket",- role_arn="arn:aws:iam::123456789012:role/test-role",- external_id="external-id-123",organization_id="org-123",)execute_calls = mock_conn.execute.call_args_list@@ -311,7 +303,7 @@ def test_verify_ducklake_copy_activity_runs_queries(monkeypatch):MagicMock(return_value=_create_mock_catalog()),)monkeypatch.setattr(- "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_cross_account_connection",+ "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_connection",MagicMock(),)@@ -460,7 +452,7 @@ def test_verify_ducklake_copy_activity_reports_failures(monkeypatch):MagicMock(return_value=_create_mock_catalog()),)monkeypatch.setattr(- "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_cross_account_connection",+ "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_connection",MagicMock(),)@@ -616,7 +608,7 @@ def test_verify_ducklake_copy_activity_respects_tolerance(monkeypatch, observed,MagicMock(return_value=_create_mock_catalog()),)monkeypatch.setattr(- "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_cross_account_connection",+ "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_connection",MagicMock(),)@@ -697,7 +689,7 @@ def test_verify_ducklake_copy_activity_includes_additional_checks(monkeypatch):MagicMock(return_value=_create_mock_catalog()),)monkeypatch.setattr(- "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_cross_account_connection",+ "posthog.temporal.ducklake.ducklake_copy_data_modeling_workflow.configure_connection",MagicMock(),)