Skip to content

Commit 880b596

Browse files
feat(dashboards): allow dashboard generation to filter for project and env (#112150)
Adds project and environment filter to dashboard artifact schema
1 parent e0918d3 commit 880b596

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/sentry/dashboards/models/generate_dashboard_artifact.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,12 @@ class GeneratedDashboard(BaseModel):
173173
"""A complete dashboard definition on a 6-column grid. Widget widths per row must sum to 6. This is the sole output artifact."""
174174

175175
title: str = Field(..., max_length=255) # Matches serializer
176+
projects: list[int] = Field(
177+
default=[],
178+
description='Project ids to scope the dashboard to. Empty list means "My Projects".',
179+
)
180+
environment: list[str] = Field(
181+
default=[],
182+
description="Environment names to filter by (e.g. ['production', 'staging']). Empty list means all environments.",
183+
)
176184
widgets: list[GeneratedWidget] = Field(..., max_items=Dashboard.MAX_WIDGETS)

src/sentry/dashboards/on_completion_hook.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ def _validate_with_serializer(
3737

3838
if project is None:
3939
return None
40+
# Strip fields that require request-scoped context (project permissions,
41+
# environment access) which we don't have in the completion hook.
42+
# The serializer validation here targets widget-level correctness.
43+
artifact_data = artifact.dict()
44+
artifact_data.pop("projects", None)
45+
artifact_data.pop("environment", None)
46+
4047
serializer = DashboardSerializer(
41-
data=artifact.dict(),
48+
data=artifact_data,
4249
context={
4350
"organization": organization,
4451
"request": SimpleNamespace(user=None), # mock request to satisfy serializer

0 commit comments

Comments
 (0)