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.

fix(data-warehouse): let users edit a table created from an uploaded file (#107751)

Tom Owers2cda62e28449
diff --git a/products/data_warehouse/backend/presentation/views/table.py b/products/data_warehouse/backend/presentation/views/table.py
index 57fde4d1024f..7d0e72758738 100644
--- a/products/data_warehouse/backend/presentation/views/table.py
+++ b/products/data_warehouse/backend/presentation/views/table.py
@@ -333,6 +333,18 @@ class TableSerializer(UserAccessControlSerializerMixin, serializers.ModelSeriali
return table
def validate_url_pattern(self, url_pattern):
+ # A credential-less table reads from PostHog's own storage by design - PostHog built the URL
+ # when the file was uploaded. Editing anything else about such a table resubmits that URL
+ # unchanged, so checking it against the owned-bucket rule below would reject every edit with
+ # an instruction the user can't follow.
+ keeps_posthog_built_url = (
+ self.instance is not None
+ and self.instance.credential_id is None
+ and url_pattern == self.instance.url_pattern
+ )
+ if keeps_posthog_built_url:
+ return url_pattern
+
is_valid, error_message = validate_warehouse_table_url_pattern(url_pattern)
if not is_valid:
raise serializers.ValidationError(error_message)
diff --git a/products/data_warehouse/backend/tests/api/test_table.py b/products/data_warehouse/backend/tests/api/test_table.py
index 56b4056f3ca4..7669298f1978 100644
--- a/products/data_warehouse/backend/tests/api/test_table.py
+++ b/products/data_warehouse/backend/tests/api/test_table.py
@@ -800,6 +800,30 @@ class TestTable(APIBaseTest):
table.refresh_from_db()
assert table.url_pattern == hosted_url
+ @override_settings(
+ DATAWAREHOUSE_BUCKET_DOMAIN="warehouse-files.posthog.example", DATAWAREHOUSE_BUCKET="ph-warehouse"
+ )
+ def test_update_keeps_the_posthog_built_url_of_an_uploaded_table(self):
+ hosted_url = "https://warehouse-files.posthog.example/file_uploads/team_1/abc/data.csv"
+ table = DataWarehouseTable.objects.create(
+ name="uploaded_table",
+ format="CSVWithNames",
+ team=self.team,
+ team_id=self.team.pk,
+ columns={},
+ url_pattern=hosted_url,
+ )
+
+ response = self.client.patch(
+ f"/api/projects/{self.team.id}/warehouse_tables/{table.id}",
+ {"name": "renamed_table", "url_pattern": hosted_url},
+ )
+
+ assert response.status_code == 200
+ table.refresh_from_db()
+ assert table.name == "renamed_table"
+ assert table.url_pattern == hosted_url
+
def test_update_can_repoint_a_table_that_has_its_own_credential(self):
from products.warehouse_sources.backend.facade.models import DataWarehouseCredential