Repository navigation
Conversation
… 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]>
…unctions Move snapshot creation and pruning out of the put() method into two dedicated functions, _take_dashboard_snapshot and _save_dashboard_revision, to keep the request handler focused on HTTP concerns. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…n.create_for_dashboard The retention policy and schema version are model-level concerns — moving them out of the endpoint and into a classmethod on DashboardRevision makes the logic reusable from any callsite without duplicating the pruning rules. The endpoint retains _take_dashboard_snapshot, which owns the API-layer concerns: feature flag check and serialization via DashboardDetailsModelSerializer. 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]>
…rd call site 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.
Add POST /organizations/{org}/dashboards/{id}/revisions/{rev_id}/restore/
that restores a dashboard to a previously saved revision.
Before overwriting the current dashboard, a snapshot of the current state
is saved as a new revision. Widget IDs are stripped from the revision
snapshot so all widgets are recreated fresh, avoiding conflicts with
widgets that no longer exist on the dashboard. The endpoint also checks
the snapshot schema version and rejects unsupported versions.
Refs DAIN-1520
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
🚨 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 |
…store Add a source parameter to DashboardRevision.create_for_dashboard (defaulting to 'edit' for backward compatibility) so the pre-restore snapshot is tagged with source='pre-restore' rather than the generic 'edit' source. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… 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.
…520-add-endpoint-to-restore-a-dashboard-revision
…-list' into shaunkaasten/dain-1520-add-endpoint-to-restore-a-dashboard-revision
Fix two bugs in the revision restore endpoint: - _take_dashboard_snapshot signature changed in a prior merge to drop the organization argument, but the restore endpoint still called it with three args, causing a TypeError on every restore request. - _prepare_restore_data stripped widget IDs but left query IDs intact. DashboardWidgetQuerySerializer skips required_for_create validation when a query has an id, bypassing fields/conditions checks. Strip query IDs too so the full creation-path validation runs. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 989a8ad. Configure here.
…st discovery Two fixes from Cursor Bugbot review: - DashboardRevision.objects.get raises ValueError when revision_id is a non-numeric string (Django raises this for integer PK fields). Add ValueError to the except clause so it returns 404 instead of 500, consistent with how OrganizationDashboardBase.convert_args handles the analogous dashboard_id lookup. - Rename PrepareRestoreDataTest to TestPrepareRestoreData so pytest auto-discovers and runs the unit tests (pytest requires class names starting with Test). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…520-add-endpoint-to-restore-a-dashboard-revision
…dpoint Cover three previously untested cases: - 403 when dashboard has explicit edit permissions that exclude the requesting user - 409 when the revision snapshot title conflicts with an existing dashboard - Widget IDs from the snapshot are not reused after restore (verifies _prepare_restore_data is wired up end-to-end) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

Add
POST /organizations/{org}/dashboards/{id}/revisions/{rev_id}/restore/to restore a dashboard to the state captured in the given revision.Before overwriting the current dashboard, the current state is snapshotted as a new revision so the restore itself is reversible. Widget IDs are stripped from the revision snapshot so all widgets are recreated fresh, avoiding conflicts with widgets that may have been replaced since the revision was taken. The endpoint also validates the snapshot schema version to guard against future format changes.
Refs DAIN-1520