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): tell users how to recover from a duplicate table name (#87395)

Tom Owersc1001c25963a
diff --git a/products/data_warehouse/backend/presentation/views/saved_query.py b/products/data_warehouse/backend/presentation/views/saved_query.py
index bbe5a66646b8..5752f8ee1121 100644
--- a/products/data_warehouse/backend/presentation/views/saved_query.py
+++ b/products/data_warehouse/backend/presentation/views/saved_query.py
@@ -1286,7 +1286,7 @@ class DataWarehouseSavedQuerySerializer(
# user-filtered, so also resolve the name team-wide using get_view_or_table_by_name.
# Otherwise a user with denied table could create another one with colliding name.
if self.context["database"].has_table(name) or get_view_or_table_by_name(self.context["team_id"], name):
- raise serializers.ValidationError("A table with this name already exists.")
+ raise serializers.ValidationError("A table or view with this name already exists. Choose a different name.")
return name
diff --git a/products/data_warehouse/backend/presentation/views/table.py b/products/data_warehouse/backend/presentation/views/table.py
index a1a7e6368643..ed2a4bace6a4 100644
--- a/products/data_warehouse/backend/presentation/views/table.py
+++ b/products/data_warehouse/backend/presentation/views/table.py
@@ -351,7 +351,9 @@ class TableSerializer(UserAccessControlSerializerMixin, serializers.ModelSeriali
# it's user-filtered, so also resolve the name team-wide using get_view_or_table_by_name.
# Otherwise a user with denied table could create another one with colliding name.
if self.context["database"].has_table(name) or get_view_or_table_by_name(self.context["team_id"], name):
- raise serializers.ValidationError("A table with this name already exists.")
+ raise serializers.ValidationError(
+ "A table or view with this name already exists. Choose a different name."
+ )
return name
@@ -738,7 +740,8 @@ class TableViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.M
database = Database.create_for(team_id=self.team_id, user=cast(User, request.user))
if database.has_table(table_name) or get_view_or_table_by_name(self.team_id, table_name):
return response.Response(
- status=status.HTTP_400_BAD_REQUEST, data={"message": "A table with this name already exists."}
+ status=status.HTTP_400_BAD_REQUEST,
+ data={"message": "A table or view with this name already exists. Choose a different name."},
)
# Confirm the object is actually there before creating a table that would fail every query.
diff --git a/products/data_warehouse/backend/tests/api/test_saved_query.py b/products/data_warehouse/backend/tests/api/test_saved_query.py
index b3aca390bb70..c767f6789a14 100644
--- a/products/data_warehouse/backend/tests/api/test_saved_query.py
+++ b/products/data_warehouse/backend/tests/api/test_saved_query.py
@@ -1880,7 +1880,7 @@ class TestSavedQuery(APIBaseTest):
},
)
assert response.status_code == 400
- assert response.json()["detail"] == "A table with this name already exists."
+ assert response.json()["detail"] == "A table or view with this name already exists. Choose a different name."
def test_update_saved_query_with_managed_viewset_fails(self):
"""Test that updating a saved query with managed viewset fails with correct 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 95a4a8ed707e..a9d138f73545 100644
--- a/products/data_warehouse/backend/tests/api/test_table.py
+++ b/products/data_warehouse/backend/tests/api/test_table.py
@@ -688,7 +688,7 @@ class TestTable(APIBaseTest):
},
)
assert response.status_code == 400
- assert response.json()["detail"] == "A table with this name already exists."
+ assert response.json()["detail"] == "A table or view with this name already exists. Choose a different name."
def test_update_table_name_to_existing_name(self):
table = DataWarehouseTable.objects.create(
@@ -704,7 +704,7 @@ class TestTable(APIBaseTest):
},
)
assert response.status_code == 400
- assert response.json()["detail"] == "A table with this name already exists."
+ assert response.json()["detail"] == "A table or view with this name already exists. Choose a different name."
def test_update_table_name_to_same_name(self):
table = DataWarehouseTable.objects.create(