diff --git a/src/sentry/dashboards/endpoints/organization_dashboards.py b/src/sentry/dashboards/endpoints/organization_dashboards.py index d6e5eadf5f109e..bba808ee5488a6 100644 --- a/src/sentry/dashboards/endpoints/organization_dashboards.py +++ b/src/sentry/dashboards/endpoints/organization_dashboards.py @@ -446,7 +446,9 @@ def post(self, request: Request, organization: Organization, retry: int = 0) -> if not features.has("organizations:dashboards-edit", organization, actor=request.user): return Response(status=404) - dashboard_count = Dashboard.objects.filter(organization=organization).count() + dashboard_count = Dashboard.objects.filter( + organization=organization, prebuilt_id=None + ).count() dashboard_limit = quotas.backend.get_dashboard_limit(organization.id) if dashboard_limit >= 0 and dashboard_count >= dashboard_limit: return Response( diff --git a/tests/sentry/dashboards/endpoints/test_organization_dashboards.py b/tests/sentry/dashboards/endpoints/test_organization_dashboards.py index 42c904a7126bf0..b80442472cead0 100644 --- a/tests/sentry/dashboards/endpoints/test_organization_dashboards.py +++ b/tests/sentry/dashboards/endpoints/test_organization_dashboards.py @@ -1893,6 +1893,36 @@ def test_dashboard_limit_prevents_creation(self, mock_get_dashboard_limit) -> No response = self.do_request("post", self.url, data={"title": "New Dashboard w/ Limit"}) assert response.status_code == 201 + @patch("sentry.quotas.backend.get_dashboard_limit") + def test_dashboard_limit_does_not_count_prebuilt_dashboards( + self, mock_get_dashboard_limit + ) -> None: + mock_get_dashboard_limit.return_value = 2 + + Dashboard.objects.create( + organization=self.organization, + title="Prebuilt Dashboard 1", + created_by_id=None, + prebuilt_id=1, + ) + Dashboard.objects.create( + organization=self.organization, + title="Prebuilt Dashboard 2", + created_by_id=None, + prebuilt_id=2, + ) + + # 2 prebuilt + 2 user dashboards + response = self.do_request("post", self.url, data={"title": "Dashboard at Limit"}) + assert response.status_code == 400 + assert response.data == "You may not exceed 2 dashboards on your current plan." + + self.dashboard.delete() + + # 2 prebuilt + 1 user dashboard + response = self.do_request("post", self.url, data={"title": "New Dashboard w/ Prebuilt"}) + assert response.status_code == 201 + def test_prebuilt_dashboard_is_shown_when_favorites_pinned_and_no_dashboards(self) -> None: # The prebuilt dashboard should not show up when filtering by owned dashboards # because it is not created by the user