Repository navigation
feat(dashboards): Add endpoint to list dashboard revisions - #113084
Conversation
|
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 807df09. Configure here.
… is enabled When the organizations:dashboards-revisions feature flag is enabled, the dashboard PUT endpoint now serializes the current dashboard state (using the existing DashboardDetailsModelSerializer) into a DashboardRevision before writing the new version. The snapshot and the save are wrapped in the same transaction so a failed update rolls back the revision too. Serialization is intentionally done outside the transaction to avoid making hybrid-cloud RPC calls (user_service.serialize_many) inside an atomic block. Revisions beyond the 10 most recent are deleted after each save to bound storage growth. Refs DAIN-1516 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Pruning and field-correctness tests for DashboardRevision.create_for_dashboard now live in test_dashboard.py, tested directly without going through HTTP. The endpoint tests are trimmed to only verify the endpoint wires up to the model correctly — they no longer re-test the model's own behaviour. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds GET /api/0/organizations/<org>/dashboards/<id>/revisions/ to return the revision history for a dashboard. Each entry includes the id, title, date saved, user, and source of the change. The endpoint is gated behind the organizations:dashboards-revisions feature flag and returns 404 for prebuilt dashboards. Results are ordered newest-first and paginated. Refs DAIN-1517 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Return only id, name, and email for the revision author instead of the full user serializer payload. Matches the pattern used by alert rules (RuleCreatedBy). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…tion The Serializer get_attrs/serialize pattern is designed to avoid N+1 queries on large lists. Since revisions are capped at 10, that overhead is not warranted here. A plain function is easier to follow. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
OrganizationDashboardBase types permission_classes as tuple[type[OrganizationDashboardsPermission]], so overriding it with OrganizationPermission caused a mypy incompatible assignment error. Removing the override uses the inherited OrganizationDashboardsPermission, which already permits GET. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…_details Removes the duplicate definition of `REVISIONS_FEATURE` in `organization_dashboard_revisions.py` and imports it from `organization_dashboard_details.py` where it is already defined, avoiding the two definitions drifting apart if the flag name changes.
719dbb0 to
4630988
Compare
…isions endpoint In cell silo mode, user_service.serialize_many raises TypeError if as_user is not an RpcUser — but request.user is a Django User. Since the endpoint is @cell_silo_endpoint, this would always crash. Drop as_user entirely; the only fields used (id, name, email) need no field-level authorization.
| @cell_silo_endpoint | ||
| class OrganizationDashboardRevisionsEndpoint(OrganizationDashboardBase): | ||
| publish_status = { | ||
| "GET": ApiPublishStatus.PRIVATE, |
There was a problem hiding this comment.
Just a note
I imagine eventually we want to make this public so ai tools like codemode can pick it up, so we'll need to also ensure openapi schema is created properly too
| def _serialize_revisions(revisions: list[DashboardRevision]) -> list[dict[str, Any]]: | ||
| user_ids = [r.created_by_id for r in revisions if r.created_by_id is not None] | ||
| users_by_id = { | ||
| u["id"]: {"id": u["id"], "name": u["name"], "email": u["email"]} | ||
| for u in user_service.serialize_many(filter={"user_ids": user_ids}) | ||
| } | ||
| return [ | ||
| { | ||
| "id": str(r.id), | ||
| "title": r.title, | ||
| "dateCreated": r.date_added, | ||
| "createdBy": users_by_id.get(str(r.created_by_id)), | ||
| "source": r.source, | ||
| } | ||
| for r in revisions | ||
| ] |
There was a problem hiding this comment.
The other dashboard models have an associated serializer, I think we should add a serializer, a lot of this would go into it. It might be more lightweight here, but i'd prefer to just keep things consistent.
And then we would call the serializer in the self.paginate.on_result
…isionSerializer class Adds DashboardRevisionSerializer (and DashboardRevisionResponse TypedDict) to the dashboard serializers module, consistent with how other dashboard models are serialized. The endpoint now calls serialize() via on_results instead of the custom _serialize_revisions helper.

Add a new endpoint for listing the revision history of a dashboard.
Endpoint:
GET /api/0/organizations/<org>/dashboards/<dashboard_id>/revisions/Each revision entry includes:
id— revision IDtitle— dashboard title at the time of savedateCreated— when the revision was savedcreatedBy— slim user object (id,name,email)source— what triggered the save (e.g."edit")The endpoint is gated behind the
organizations:dashboards-revisionsfeature flag and returns 404 for prebuilt dashboards. Results are ordered newest-first and paginated. Up to 10 revisions are retained per dashboard (enforced at write time by the base branch).This PR stacks on top of
skaasten/feat/dashboard-revision-snapshot-on-save, which adds theDashboardRevisionmodel and the snapshot-on-save logic.Refs DAIN-1517