Skip to content

feat(dashboards): Add endpoint to list dashboard revisions - #113084

Merged
skaasten merged 10 commits into
masterfrom
skaasten/feat/dashboard-revision-list
Apr 17, 2026
Merged

skaasten merged 10 commits into
masterfrom
skaasten/feat/dashboard-revision-list

Conversation

@skaasten

Copy link
Copy Markdown
Contributor

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 ID
  • title — dashboard title at the time of save
  • dateCreated — when the revision was saved
  • createdBy — slim user object (id, name, email)
  • source — what triggered the save (e.g. "edit")

The endpoint is gated behind the organizations:dashboards-revisions feature 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 the DashboardRevision model and the snapshot-on-save logic.

Refs DAIN-1517

@linear-code

linear-code Bot commented Apr 15, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 15, 2026
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 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 #discuss-dev-infra channel.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Base automatically changed from skaasten/feat/dashboard-revision-snapshot-on-save to master April 17, 2026 13:55
@skaasten
skaasten requested a review from a team as a code owner April 17, 2026 13:55
skaasten and others added 8 commits April 17, 2026 10:03
… 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.
…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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +22 to +37
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
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DominikB2014 DominikB2014 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@skaasten
skaasten merged commit d766f02 into master Apr 17, 2026
58 checks passed
@skaasten
skaasten deleted the skaasten/feat/dashboard-revision-list branch April 17, 2026 15:27
@github-actions github-actions Bot locked and limited conversation to collaborators May 3, 2026

This branch was successfully deployed

1 active deployment
Preview — ab7d7248 Deployed Apr 17, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants