: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(dashboards): expose filters in dashboard PATCH OpenAPI schema (#64200)
Thomas Obermüller7b81d189db38
diff --git a/products/dashboards/backend/api/test/test_dashboard_openapi.py b/products/dashboards/backend/api/test/test_dashboard_openapi.pyindex e61f9c5c3caa..9a320aad3600 100644--- a/products/dashboards/backend/api/test/test_dashboard_openapi.py+++ b/products/dashboards/backend/api/test/test_dashboard_openapi.py@@ -1,4 +1,5 @@from drf_spectacular.generators import SchemaGenerator+from rest_framework import serializersfrom products.dashboards.backend.api.test.dashboard_openapi_test_helpers import (dashboard_patch_runtime_openapi_field_names,@@ -39,3 +40,19 @@ class TestDashboardPatchOpenApiContract:"Generated OpenAPI schema for dashboard PATCH must include every agent-facing runtime field. "f"Missing: {sorted(missing)}.")++ def test_filters_documented_as_writable_patch_field(self) -> None:+ # filters is a SerializerMethodField on DashboardSerializer (read-only in the inferred schema),+ # so it is excluded from dashboard_patch_runtime_openapi_field_names(). The PATCH runtime accepts and+ # persists it, so PatchedDashboardOpenApiSerializer must document it explicitly for agents/MCP.+ openapi_fields = PatchedDashboardOpenApiSerializer().fields+ assert "filters" in openapi_fields, (+ "PatchedDashboardOpenApiSerializer must document the writable 'filters' field so the dashboard-update "+ "MCP tool can set dashboard-level date/property filters."+ )+ filters_field = openapi_fields["filters"]+ assert isinstance(filters_field, serializers.Serializer)+ filters_fields = frozenset(filters_field.fields.keys())+ assert {"date_from", "date_to", "properties"}.issubset(filters_fields), (+ f"Dashboard filters schema must expose date_from/date_to/properties. Got: {sorted(filters_fields)}."+ )diff --git a/products/dashboards/backend/widget_specs/openapi.py b/products/dashboards/backend/widget_specs/openapi.pyindex 7c6c41aefe19..1a954b7e102f 100644--- a/products/dashboards/backend/widget_specs/openapi.py+++ b/products/dashboards/backend/widget_specs/openapi.py@@ -194,6 +194,30 @@ class DashboardPatchTileOpenApiSerializer(serializers.Serializer):widget = DashboardPatchWidgetOpenApiSerializer(required=False, help_text="Nested widget row updates.")+class DashboardFiltersOpenApiSerializer(serializers.Serializer):+ """OpenAPI-only shape for a dashboard's filters object (agents/MCP).++ Documents the dashboard-level filters that act as the single source of truth for the+ dashboard's tiles. Runtime persistence reads the raw ``filters`` dict from the request body, so+ extra keys are accepted, but these are the ones agents should set.+ """++ date_from = serializers.CharField(+ required=False,+ allow_null=True,+ help_text="Dashboard-level start of the date range, e.g. '-30d', '-7d', or an ISO date. Applies to all tiles.",+ )+ date_to = serializers.CharField(+ required=False,+ allow_null=True,+ help_text="Dashboard-level end of the date range, e.g. '-1d' or an ISO date. Null/omitted means up to now.",+ )+ properties = serializers.JSONField(+ required=False,+ help_text="Dashboard-level property filters applied to every tile (PostHog property filter group).",+ )++class PatchedDashboardOpenApiSerializer(serializers.Serializer):"""OpenAPI-only PATCH body for dashboards (agents/MCP).@@ -204,6 +228,10 @@ class PatchedDashboardOpenApiSerializer(serializers.Serializer):name = serializers.CharField(max_length=400, required=False, allow_null=True)description = serializers.CharField(required=False, allow_blank=True)pinned = serializers.BooleanField(required=False)+ filters = DashboardFiltersOpenApiSerializer(+ required=False,+ help_text="Dashboard-level filters (date range and properties) applied across all tiles as the source of truth.",+ )breakdown_colors = serializers.JSONField(required=False,help_text="Custom color mapping for breakdown values.",diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex d66c865c4d2f..29dea65ad26c 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -389,6 +389,28 @@ export interface DashboardCollaboratorApi {user_uuid: string}+/**+ * OpenAPI-only shape for a dashboard's filters object (agents/MCP).+ *+ * Documents the dashboard-level filters that act as the single source of truth for the+ * dashboard's tiles. Runtime persistence reads the raw ``filters`` dict from the request body, so+ * extra keys are accepted, but these are the ones agents should set.+ */+export interface DashboardFiltersOpenApiApi {+ /**+ * Dashboard-level start of the date range, e.g. '-30d', '-7d', or an ISO date. Applies to all tiles.+ * @nullable+ */+ date_from?: string | null+ /**+ * Dashboard-level end of the date range, e.g. '-1d' or an ISO date. Null/omitted means up to now.+ * @nullable+ */+ date_to?: string | null+ /** Dashboard-level property filters applied to every tile (PostHog property filter group). */+ properties?: unknown+}+/*** * `activity_events_list` - activity_events_list* * `error_tracking_list` - error_tracking_list@@ -721,6 +743,8 @@ export interface PatchedPatchedDashboardOpenApiApi {name?: string | nulldescription?: stringpinned?: boolean+ /** Dashboard-level filters (date range and properties) applied across all tiles as the source of truth. */+ filters?: DashboardFiltersOpenApiApi/** Custom color mapping for breakdown values. */breakdown_colors?: unknown/**diff --git a/products/dashboards/frontend/generated/api.zod.ts b/products/dashboards/frontend/generated/api.zod.tsindex 4063fc104308..214d086be79f 100644--- a/products/dashboards/frontend/generated/api.zod.ts+++ b/products/dashboards/frontend/generated/api.zod.ts@@ -246,6 +246,34 @@ export const DashboardsPartialUpdateBody = /* @__PURE__ */ zodname: zod.string().max(dashboardsPartialUpdateBodyNameMax).nullish(),description: zod.string().optional(),pinned: zod.boolean().optional(),+ filters: zod+ .object({+ date_from: zod+ .string()+ .nullish()+ .describe(+ "Dashboard-level start of the date range, e.g. '-30d', '-7d', or an ISO date. Applies to all tiles."+ ),+ date_to: zod+ .string()+ .nullish()+ .describe(+ "Dashboard-level end of the date range, e.g. '-1d' or an ISO date. Null\/omitted means up to now."+ ),+ properties: zod+ .unknown()+ .optional()+ .describe(+ 'Dashboard-level property filters applied to every tile (PostHog property filter group).'+ ),+ })+ .describe(+ "OpenAPI-only shape for a dashboard's filters object (agents\/MCP).\n\nDocuments the dashboard-level filters that act as the single source of truth for the\ndashboard's tiles. Runtime persistence reads the raw ``filters`` dict from the request body, so\nextra keys are accepted, but these are the ones agents should set."+ )+ .optional()+ .describe(+ 'Dashboard-level filters (date range and properties) applied across all tiles as the source of truth.'+ ),breakdown_colors: zod.unknown().optional().describe('Custom color mapping for breakdown values.'),data_color_theme_id: zod.number().nullish().describe('ID of the color theme used for chart visualizations.'),tags: zod.array(zod.string()).optional(),diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex d74ccbe8e983..f462fb3b2fc1 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -14337,6 +14337,28 @@ export namespace Schemas {properties?: (EventPropertyFilter | PersonPropertyFilter | ElementPropertyFilter | EventMetadataPropertyFilter | SessionPropertyFilter | CohortPropertyFilter | RecordingPropertyFilter | LogEntryPropertyFilter | GroupPropertyFilter | FeaturePropertyFilter | FlagPropertyFilter | HogQLPropertyFilter | EmptyPropertyFilter | DataWarehousePropertyFilter | DataWarehousePersonPropertyFilter | ErrorTrackingIssueFilter | LogPropertyFilter | SpanPropertyFilter | RevenueAnalyticsPropertyFilter | WorkflowVariablePropertyFilter)[] | null;}+ /**+ * OpenAPI-only shape for a dashboard's filters object (agents/MCP).+ *+ * Documents the dashboard-level filters that act as the single source of truth for the+ * dashboard's tiles. Runtime persistence reads the raw ``filters`` dict from the request body, so+ * extra keys are accepted, but these are the ones agents should set.+ */+ export interface DashboardFiltersOpenApi {+ /**+ * Dashboard-level start of the date range, e.g. '-30d', '-7d', or an ISO date. Applies to all tiles.+ * @nullable+ */+ date_from?: string | null;+ /**+ * Dashboard-level end of the date range, e.g. '-1d' or an ISO date. Null/omitted means up to now.+ * @nullable+ */+ date_to?: string | null;+ /** Dashboard-level property filters applied to every tile (PostHog property filter group). */+ properties?: unknown;+ }+/*** * `activity_events_list` - activity_events_list* * `error_tracking_list` - error_tracking_list@@ -37665,6 +37687,8 @@ export namespace Schemas {name?: string | null;description?: string;pinned?: boolean;+ /** Dashboard-level filters (date range and properties) applied across all tiles as the source of truth. */+ filters?: DashboardFiltersOpenApi;/** Custom color mapping for breakdown values. */breakdown_colors?: unknown;/**diff --git a/services/mcp/src/generated/dashboards/api.ts b/services/mcp/src/generated/dashboards/api.tsindex c4f3701fd44f..e88330c05f9d 100644--- a/services/mcp/src/generated/dashboards/api.ts+++ b/services/mcp/src/generated/dashboards/api.ts@@ -148,6 +148,34 @@ export const DashboardsPartialUpdateBody = /* @__PURE__ */ zodname: zod.string().max(dashboardsPartialUpdateBodyNameMax).nullish(),description: zod.string().optional(),pinned: zod.boolean().optional(),+ filters: zod+ .object({+ date_from: zod+ .string()+ .nullish()+ .describe(+ "Dashboard-level start of the date range, e.g. '-30d', '-7d', or an ISO date. Applies to all tiles."+ ),+ date_to: zod+ .string()+ .nullish()+ .describe(+ "Dashboard-level end of the date range, e.g. '-1d' or an ISO date. Null/omitted means up to now."+ ),+ properties: zod+ .unknown()+ .optional()+ .describe(+ 'Dashboard-level property filters applied to every tile (PostHog property filter group).'+ ),+ })+ .describe(+ "OpenAPI-only shape for a dashboard's filters object (agents/MCP).\n\nDocuments the dashboard-level filters that act as the single source of truth for the\ndashboard's tiles. Runtime persistence reads the raw ``filters`` dict from the request body, so\nextra keys are accepted, but these are the ones agents should set."+ )+ .optional()+ .describe(+ 'Dashboard-level filters (date range and properties) applied across all tiles as the source of truth.'+ ),breakdown_colors: zod.unknown().optional().describe('Custom color mapping for breakdown values.'),data_color_theme_id: zod.number().nullish().describe('ID of the color theme used for chart visualizations.'),tags: zod.array(zod.string()).optional(),diff --git a/services/mcp/src/tools/generated/dashboards.ts b/services/mcp/src/tools/generated/dashboards.tsindex a27c7052e45a..3bbd14a14aca 100644--- a/services/mcp/src/tools/generated/dashboards.ts+++ b/services/mcp/src/tools/generated/dashboards.ts@@ -374,6 +374,9 @@ const dashboardUpdate = (): ToolBase<typeof DashboardUpdateSchema, WithPostHogUrif (params.pinned !== undefined) {body['pinned'] = params.pinned}+ if (params.filters !== undefined) {+ body['filters'] = params.filters+ }if (params.breakdown_colors !== undefined) {body['breakdown_colors'] = params.breakdown_colors}diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.jsonindex 44c5956c7825..78c553934feb 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.json@@ -22,6 +22,37 @@"description": {"type": "string"},+ "filters": {+ "description": "Dashboard-level filters (date range and properties) applied across all tiles as the source of truth.",+ "properties": {+ "date_from": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "Dashboard-level start of the date range, e.g. '-30d', '-7d', or an ISO date. Applies to all tiles."+ },+ "date_to": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "Dashboard-level end of the date range, e.g. '-1d' or an ISO date. Null/omitted means up to now."+ },+ "properties": {+ "description": "Dashboard-level property filters applied to every tile (PostHog property filter group)."+ }+ },+ "type": "object"+ },"id": {"description": "A unique integer value identifying this dashboard.","type": "number"