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.

feat(subscriptions): allow 10 dashboard insights (#78509)

Matt Pua314771a537ba
diff --git a/ee/api/subscription.py b/ee/api/subscription.py
index 577d95d30482..53021106e5ce 100644
--- a/ee/api/subscription.py
+++ b/ee/api/subscription.py
@@ -67,7 +67,7 @@ from products.product_analytics.backend.models.insight import Insight
from ee.billing.quota_limiting import QuotaLimitingCaches, QuotaResource, is_team_limited
from ee.tasks.subscriptions.auto_disable import validate_re_enable
-from ee.tasks.subscriptions.subscription_utils import MAX_DASHBOARD_INSIGHTS
+from ee.tasks.subscriptions.subscription_utils import MAX_INSIGHTS
SUMMARY_QUOTA_CACHE_TTL_SECONDS = 60
SUMMARY_CAP_HIT_DEDUPE_TTL_SECONDS = 600
@@ -234,7 +234,7 @@ class SubscriptionSerializer(serializers.ModelSerializer):
)
dashboard_export_insights = DashboardExportInsightsField(
required=False,
- help_text="List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.",
+ help_text="List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.",
)
ai_prompt_config = AIPromptConfigSerializer(
required=False,
@@ -671,9 +671,9 @@ class SubscriptionSerializer(serializers.ModelSerializer):
if dashboard_export_insights:
selected_ids = set(dashboard_export_insights)
- if len(selected_ids) > MAX_DASHBOARD_INSIGHTS:
+ if len(selected_ids) > MAX_INSIGHTS:
raise ValidationError(
- {"dashboard_export_insights": [f"Cannot select more than {MAX_DASHBOARD_INSIGHTS} insights."]}
+ {"dashboard_export_insights": [f"Cannot select more than {MAX_INSIGHTS} insights."]}
)
# Ensure all selected insights belong to the team
diff --git a/ee/api/test/test_subscription.py b/ee/api/test/test_subscription.py
index 9bc83536f843..fb671d3d8ccd 100644
--- a/ee/api/test/test_subscription.py
+++ b/ee/api/test/test_subscription.py
@@ -41,6 +41,7 @@ from products.product_analytics.backend.models.insight import Insight
from ee.api.test.base import APILicensedTest
from ee.models.rbac.access_control import AccessControl
from ee.tasks.subscriptions.slack_subscriptions import get_slack_integration_for_team
+from ee.tasks.subscriptions.subscription_utils import MAX_INSIGHTS
class TestSubscriptionTemporal(APILicensedTest):
@@ -541,9 +542,9 @@ class TestSubscriptionTemporal(APILicensedTest):
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json()["attr"] == "dashboard_export_insights"
- def test_cannot_create_dashboard_subscription_with_too_many_insights(self):
+ def test_dashboard_subscription_enforces_maximum_insights(self):
insights = []
- for _ in range(7):
+ for _ in range(MAX_INSIGHTS + 1):
insight = Insight.objects.create(
filters=Filter(data=self.insight_filter_dict).to_dict(),
team=self.team,
@@ -552,22 +553,31 @@ class TestSubscriptionTemporal(APILicensedTest):
self.dashboard.tiles.create(insight=insight)
insights.append(insight)
+ payload = {
+ "dashboard": self.dashboard.id,
+ "target_type": "email",
+ "target_value": "[email protected]",
+ "frequency": "weekly",
+ "interval": 1,
+ "start_date": "2022-01-01T00:00:00",
+ "title": "Dashboard Subscription",
+ }
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/subscriptions",
+ {**payload, "dashboard_export_insights": [i.id for i in insights[:MAX_INSIGHTS]]},
+ )
+ assert response.status_code == status.HTTP_201_CREATED
+
response = self.client.post(
f"/api/projects/{self.team.id}/subscriptions",
{
- "dashboard": self.dashboard.id,
+ **payload,
"dashboard_export_insights": [i.id for i in insights], # exceeds limit
- "target_type": "email",
- "target_value": "[email protected]",
- "frequency": "weekly",
- "interval": 1,
- "start_date": "2022-01-01T00:00:00",
- "title": "Dashboard Subscription",
},
)
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json()["attr"] == "dashboard_export_insights"
- assert "Cannot select more than 6 insights" in response.json()["detail"]
+ assert f"Cannot select more than {MAX_INSIGHTS} insights" in response.json()["detail"]
def test_cannot_create_dashboard_subscription_with_insights_from_other_dashboard(self):
# Create an insight that belongs to a different dashboard
diff --git a/ee/tasks/subscriptions/subscription_utils.py b/ee/tasks/subscriptions/subscription_utils.py
index b84c95be69c6..723d762c98fb 100644
--- a/ee/tasks/subscriptions/subscription_utils.py
+++ b/ee/tasks/subscriptions/subscription_utils.py
@@ -19,7 +19,7 @@ logger = structlog.get_logger(__name__)
UTM_TAGS_BASE = "utm_source=posthog&utm_campaign=subscription_report"
# Keep in sync with MAX_INSIGHTS in products/subscriptions/frontend/components/Subscriptions/insightSelectorLogic.ts.
-MAX_DASHBOARD_INSIGHTS = 6
+MAX_INSIGHTS = 10
ASSET_GENERATION_FAILED_MESSAGE = "Failed to generate content"
# Prometheus metrics for Temporal workers (web/worker pods)
SUBSCRIPTION_ASSET_GENERATION_TIMER = Histogram(
@@ -36,7 +36,7 @@ def _has_asset_failed(asset: ExportedAsset) -> bool:
def generate_assets(
resource: Union[Subscription, SharingConfiguration],
- max_asset_count: int = MAX_DASHBOARD_INSIGHTS,
+ max_asset_count: int = MAX_INSIGHTS,
) -> tuple[list[Insight], list[ExportedAsset]]:
with SUBSCRIPTION_ASSET_GENERATION_TIMER.labels(execution_path="celery").time():
if resource.dashboard:
diff --git a/ee/tasks/test/subscriptions/test_subscriptions_utils.py b/ee/tasks/test/subscriptions/test_subscriptions_utils.py
index 4b57d88e4b25..0954b1a31c39 100644
--- a/ee/tasks/test/subscriptions/test_subscriptions_utils.py
+++ b/ee/tasks/test/subscriptions/test_subscriptions_utils.py
@@ -7,7 +7,7 @@ from products.dashboards.backend.models.dashboard_tile import DashboardTile
from products.exports.backend.models.exported_asset import ExportedAsset
from products.product_analytics.backend.models.insight import Insight
-from ee.tasks.subscriptions.subscription_utils import MAX_DASHBOARD_INSIGHTS, generate_assets
+from ee.tasks.subscriptions.subscription_utils import MAX_INSIGHTS, generate_assets
from ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscription
@@ -44,8 +44,8 @@ class TestSubscriptionsTasksUtils(APIBaseTest):
insights, assets = generate_assets(subscription)
assert len(insights) == len(self.tiles)
- assert len(assets) == MAX_DASHBOARD_INSIGHTS
- assert mock_export_task.si.call_count == MAX_DASHBOARD_INSIGHTS
+ assert len(assets) == MAX_INSIGHTS
+ assert mock_export_task.si.call_count == MAX_INSIGHTS
def test_raises_if_missing_resource(self, _mock_export_task: MagicMock, _mock_group: MagicMock) -> None:
subscription = create_subscription(team=self.team, created_by=self.user)
diff --git a/products/exports/backend/temporal/subscriptions/activities.py b/products/exports/backend/temporal/subscriptions/activities.py
index 32fc018ec45b..f24678b80fa4 100644
--- a/products/exports/backend/temporal/subscriptions/activities.py
+++ b/products/exports/backend/temporal/subscriptions/activities.py
@@ -52,7 +52,7 @@ from ee.tasks.subscriptions.auto_disable import (
)
from ee.tasks.subscriptions.email_subscriptions import send_email_subscription_report
from ee.tasks.subscriptions.slack_subscriptions import send_slack_message_with_integration_async
-from ee.tasks.subscriptions.subscription_utils import MAX_DASHBOARD_INSIGHTS
+from ee.tasks.subscriptions.subscription_utils import MAX_INSIGHTS
LOGGER = get_logger(__name__)
@@ -257,7 +257,7 @@ async def create_export_assets(inputs: CreateExportAssetsInputs) -> CreateExport
subscription_id=inputs.subscription_id,
)
- max_asset_count = inputs.max_asset_count if inputs.max_asset_count is not None else MAX_DASHBOARD_INSIGHTS
+ max_asset_count = inputs.max_asset_count if inputs.max_asset_count is not None else MAX_INSIGHTS
if max_asset_count <= 0:
raise ApplicationError(
f"Dashboard insight export limit must be at least 1, received {max_asset_count} for subscription {inputs.subscription_id}",
diff --git a/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx b/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx
index 37bba559a60c..2e285fcb73cf 100644
--- a/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx
+++ b/products/subscriptions/frontend/components/Subscriptions/InsightSelector.test.tsx
@@ -121,15 +121,15 @@ describe('InsightSelector', () => {
})
it('shows max limit message when at capacity', () => {
- const sixInsightTiles = Array.from({ length: 6 }, (_, i) => ({
+ const maxInsightTiles = Array.from({ length: MAX_INSIGHTS }, (_, i) => ({
id: i + 1,
insight: { id: 100 + i, name: `Insight ${i}` } as any,
layouts: { sm: { x: 0, y: i } } as any,
}))
- const selectedIds = sixInsightTiles.map((t) => t.insight.id)
+ const selectedIds = maxInsightTiles.map((t) => t.insight.id)
renderInsightSelector({
- tiles: sixInsightTiles as DashboardTile[],
+ tiles: maxInsightTiles as DashboardTile[],
selectedInsightIds: selectedIds,
onChange: jest.fn(),
})
diff --git a/products/subscriptions/frontend/components/Subscriptions/insightSelectorLogic.ts b/products/subscriptions/frontend/components/Subscriptions/insightSelectorLogic.ts
index 341fc46efe94..27da477fd11b 100644
--- a/products/subscriptions/frontend/components/Subscriptions/insightSelectorLogic.ts
+++ b/products/subscriptions/frontend/components/Subscriptions/insightSelectorLogic.ts
@@ -2,8 +2,8 @@ import { MakeLogicType, actions, kea, path, props, reducers, selectors } from 'k
import { DashboardTile, InsightModel } from '~/types'
-// Keep in sync with DEFAULT_MAX_ASSET_COUNT in ee/tasks/subscriptions/subscription_utils.py
-export const MAX_INSIGHTS = 6
+// Keep in sync with MAX_INSIGHTS in ee/tasks/subscriptions/subscription_utils.py
+export const MAX_INSIGHTS = 10
export interface InsightSelectorLogicProps {
tiles: DashboardTile[]
diff --git a/products/subscriptions/frontend/generated/api.schemas.ts b/products/subscriptions/frontend/generated/api.schemas.ts
index 81d5efd28363..937eb8fd3b21 100644
--- a/products/subscriptions/frontend/generated/api.schemas.ts
+++ b/products/subscriptions/frontend/generated/api.schemas.ts
@@ -194,7 +194,7 @@ export interface SubscriptionApi {
readonly insight_short_id: string | null
/** @nullable */
readonly resource_name: string | null
- /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6. */
+ /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10. */
dashboard_export_insights?: number[]
/**
* Free-text prompt that drives the AI-generated report. Required when resource_type is 'ai_prompt'. Max 4000 characters.
@@ -342,7 +342,7 @@ export interface PatchedSubscriptionApi {
readonly insight_short_id?: string | null
/** @nullable */
readonly resource_name?: string | null
- /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6. */
+ /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10. */
dashboard_export_insights?: number[]
/**
* Free-text prompt that drives the AI-generated report. Required when resource_type is 'ai_prompt'. Max 4000 characters.
diff --git a/products/subscriptions/frontend/generated/api.zod.ts b/products/subscriptions/frontend/generated/api.zod.ts
index 42e77f65e40b..2162b317d589 100644
--- a/products/subscriptions/frontend/generated/api.zod.ts
+++ b/products/subscriptions/frontend/generated/api.zod.ts
@@ -41,7 +41,7 @@ export const SubscriptionsCreateBody = /* @__PURE__ */ zod
.array(zod.number())
.optional()
.describe(
- 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.'
+ 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.'
),
prompt: zod
.string()
@@ -211,7 +211,7 @@ export const SubscriptionsUpdateBody = /* @__PURE__ */ zod
.array(zod.number())
.optional()
.describe(
- 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.'
+ 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.'
),
prompt: zod
.string()
@@ -381,7 +381,7 @@ export const SubscriptionsPartialUpdateBody = /* @__PURE__ */ zod
.array(zod.number())
.optional()
.describe(
- 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.'
+ 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.'
),
prompt: zod
.string()
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index f58ec5cd9dd1..8e26808c6c80 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -48338,7 +48338,7 @@ export namespace Schemas {
readonly insight_short_id: string | null;
/** @nullable */
readonly resource_name: string | null;
- /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6. */
+ /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10. */
dashboard_export_insights?: number[];
/**
* Free-text prompt that drives the AI-generated report. Required when resource_type is 'ai_prompt'. Max 4000 characters.
@@ -56508,7 +56508,7 @@ export namespace Schemas {
readonly insight_short_id?: string | null;
/** @nullable */
readonly resource_name?: string | null;
- /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6. */
+ /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10. */
dashboard_export_insights?: number[];
/**
* Free-text prompt that drives the AI-generated report. Required when resource_type is 'ai_prompt'. Max 4000 characters.
diff --git a/services/mcp/src/generated/subscriptions/api.ts b/services/mcp/src/generated/subscriptions/api.ts
index 799f1e4294f2..ea99289928c2 100644
--- a/services/mcp/src/generated/subscriptions/api.ts
+++ b/services/mcp/src/generated/subscriptions/api.ts
@@ -76,7 +76,7 @@ export const SubscriptionsCreateBody = /* @__PURE__ */ zod
.array(zod.number())
.optional()
.describe(
- 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.'
+ 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.'
),
prompt: zod
.string()
@@ -259,7 +259,7 @@ export const SubscriptionsPartialUpdateBody = /* @__PURE__ */ zod
.array(zod.number())
.optional()
.describe(
- 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.'
+ 'List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.'
),
prompt: zod
.string()
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.json
index 4e2bfd746b98..008403477f26 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-create.json
@@ -100,7 +100,7 @@
"description": "Dashboard ID to subscribe to (mutually exclusive with insight on create)."
},
"dashboard_export_insights": {
- "description": "List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.",
+ "description": "List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.",
"items": {
"type": "number"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.json
index 68048c056b97..61e4c2d572c5 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/subscriptions-partial-update.json
@@ -99,7 +99,7 @@
"description": "Dashboard ID to subscribe to (mutually exclusive with insight on create)."
},
"dashboard_export_insights": {
- "description": "List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 6.",
+ "description": "List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 10.",
"items": {
"type": "number"
},