: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(welcome): use insight short_id in activity links (#93708)
Ryan McCrary992b4efa00a9
diff --git a/posthog/api/test/test_welcome.py b/posthog/api/test/test_welcome.pyindex e8e137802225..a7d3e9d40b95 100644--- a/posthog/api/test/test_welcome.py+++ b/posthog/api/test/test_welcome.py@@ -140,6 +140,47 @@ class TestWelcomeEndpoint(APIBaseTest):self.assertEqual(len(data["recent_activity"]), 1)self.assertEqual(data["recent_activity"][0]["entity_name"], "My insight")+ def test_recent_activity_insight_url_uses_short_id(self):+ ActivityLog.objects.create(+ team_id=self.team.id,+ organization_id=self.organization.id,+ scope="Insight",+ activity="created",+ item_id="1001",+ detail={"name": "My insight", "short_id": "AaVQ8Ijw"},+ user=self.user,+ is_system=False,+ was_impersonated=False,+ )+ ActivityLog.objects.create(+ team_id=self.team.id,+ organization_id=self.organization.id,+ scope="Insight",+ activity="created",+ item_id="123",+ detail={"name": "Legacy insight"},+ user=self.user,+ is_system=False,+ was_impersonated=False,+ )+ ActivityLog.objects.create(+ team_id=self.team.id,+ organization_id=self.organization.id,+ scope="Dashboard",+ activity="created",+ item_id="42",+ detail={"name": "My dashboard"},+ user=self.user,+ is_system=False,+ was_impersonated=False,+ )+ response = self.client.get("/api/organizations/@current/welcome/current/")+ data = response.json()+ urls_by_name = {item["entity_name"]: item["entity_url"] for item in data["recent_activity"]}+ self.assertEqual(urls_by_name["My insight"], f"/project/{self.team.id}/insights/AaVQ8Ijw")+ self.assertIsNone(urls_by_name["Legacy insight"])+ self.assertEqual(urls_by_name["My dashboard"], f"/project/{self.team.id}/dashboard/42")+def test_recent_activity_truncates_long_entity_names(self):ActivityLog.objects.create(team_id=self.team.id,diff --git a/posthog/api/welcome.py b/posthog/api/welcome.pyindex 6cfbd1d784b7..c752fa1692ed 100644--- a/posthog/api/welcome.py+++ b/posthog/api/welcome.py@@ -49,6 +49,16 @@ _SCOPE_URL_BUILDERS = {"Survey": lambda team_id, item_id: f"/project/{team_id}/surveys/{item_id}",}++def _activity_path_id(scope: str, item_id: str | None, detail: dict[str, Any]) -> str | None:+ # Insight scene routes look up by short_id. Activity log item_id is the numeric PK, so a+ # `/insights/<pk>` link 404s even though the insight exists.+ if scope == "Insight":+ short_id = detail.get("short_id")+ return short_id if isinstance(short_id, str) and short_id else None+ return item_id++_RECENT_ACTIVITY_MAX_ITEMS = 10_POPULAR_DASHBOARDS_MAX_ITEMS = 3_TEAM_MEMBERS_MAX_ITEMS = 8@@ -454,8 +464,9 @@ def _format_activity_row(row: ActivityLog, team_ids: list[int]) -> dict[str, Anyentity_url = Noneurl_builder = _SCOPE_URL_BUILDERS.get(row.scope)- if url_builder is not None and row.item_id and row.team_id:- entity_url = url_builder(row.team_id, row.item_id)+ path_id = _activity_path_id(row.scope, row.item_id, detail)+ if url_builder is not None and path_id and row.team_id:+ entity_url = url_builder(row.team_id, path_id)timestamp = row.created_atif timezone.is_naive(timestamp):