Skip to content

fix(dashboard): Align revision schema with actual API response#1000

Merged
MathurAditya724 merged 2 commits into
mainfrom
fix/dashboard-revision-schema
May 21, 2026
Merged

fix(dashboard): Align revision schema with actual API response#1000
MathurAditya724 merged 2 commits into
mainfrom
fix/dashboard-revision-schema

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior Bot commented May 21, 2026

The DashboardRevisionSchema didn't match the actual Sentry API response from DashboardRevisionSerializer, causing Zod validation failures when running sentry dashboard revisions.

Root cause: The schema expected { id: number, version: number, dashboardId: number } but the API returns { id: string, title: string, createdBy: object | null, source: string }. The version and dashboardId fields don't exist in the API response at all.

Changes:

  • src/types/dashboard.ts — Rebuilt DashboardRevisionSchema to match the actual serializer response: string id, title, nullable createdBy (with nested user fields), and source
  • src/lib/api/dashboards.ts — Changed restoreDashboardRevision() to accept string revision IDs (with encodeURIComponent)
  • src/commands/dashboard/restore.ts--revision flag now accepts string IDs instead of requiring positive integers
  • src/commands/dashboard/revisions.ts — Replaced VERSION column with TITLE and AUTHOR columns; fixed restore hint to include --revision flag
  • Tests updated to use the actual API response shape

Verified: All 20 dashboard revision/restore tests pass. 6 pre-existing failures in widget tests are unrelated (importOriginal Bun/vitest compat issue).

Fixes #935

Action taken on behalf of Sergiy Dybskiy.


View Session in Sentry

The DashboardRevisionSchema expected numeric id, version, and
dashboardId fields, but the Sentry API returns string id, title,
createdBy, and source. This caused Zod validation failures when
running `sentry dashboard revisions`.

- Change id from z.number() to z.string()
- Remove non-existent version and dashboardId fields
- Add title, createdBy (nullable), and source fields
- Update restore command to accept string revision IDs
- Update revisions formatter to show title and author columns

Fixes #935

Co-authored-by: Sergiy Dybskiy <sergiy.dybskiy@sentry.io>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1000/

Built to branch gh-pages at 2026-05-21 19:37 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link
Copy Markdown
Member

@MathurAditya724 MathurAditya724 left a comment

Choose a reason for hiding this comment

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

verified the new DashboardRevisionSchema against the actual DashboardRevisionSerializer in getsentry/sentry — fields match exactly (id: str, title, dateCreated, createdBy: {id, name, email, avatarType, avatarUrl} | null, source).

all 20 dashboard revision/restore tests pass. the 3 typecheck errors are pre-existing (missing generated files), unrelated to this change.

the author fallback chain (name → email → id → "—") and encodeURIComponent on the revision ID in the restore URL are both good defensive choices. .passthrough() on the Zod schemas gives forward-compat if the API adds fields later.

lgtm — ready to take out of draft once CI is green.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Codecov Results 📊

❌ Patch coverage is 42.86%. Project has 4289 uncovered lines.
❌ Project coverage is 81.63%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/commands/dashboard/restore.ts 0.00% ⚠️ 3 Missing
src/lib/api/dashboards.ts 0.00% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    81.64%    81.63%    -0.01%
==========================================
  Files          328       328         —
  Lines        23341     23344        +3
  Branches     15109     15111        +2
==========================================
+ Hits         19056     19055        -1
- Misses        4285      4289        +4
- Partials      1613      1615        +2

Generated by Codecov Action

@MathurAditya724
Copy link
Copy Markdown
Member

fix-ci: attempt 1 — biome formatter wants different line wrapping in revisions.ts and restore.test.ts, running lint:fix

@MathurAditya724 MathurAditya724 marked this pull request as ready for review May 21, 2026 19:44
@MathurAditya724 MathurAditya724 merged commit 0a8d7d0 into main May 21, 2026
29 checks passed
@MathurAditya724 MathurAditya724 deleted the fix/dashboard-revision-schema branch May 21, 2026 19:45
version: String(r.version),
id: r.id,
title: escapeMarkdownCell(r.title),
author: r.createdBy?.name ?? r.createdBy?.email ?? r.createdBy?.id ?? "—",
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.

Bug: The author field is not escaped with escapeMarkdownCell, which can break markdown table rendering if a user's name or email contains special characters like |.
Severity: LOW

Suggested Fix

Wrap the author value assignment with the escapeMarkdownCell() helper function to ensure any special characters are properly escaped before being rendered in the table.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/commands/dashboard/revisions.ts#L75

Potential issue: The `author` field, which is populated using `r.createdBy?.name`,
`r.createdBy?.email`, or `r.createdBy?.id`, is not being escaped before it is rendered
in a markdown table. If any of these values contain special markdown characters like a
pipe (`|`), it will be interpreted as a table column separator. This will break the
table's structure and corrupt the command's output for dashboards where an author's
details contain such characters. Other parts of the codebase, like
`src/commands/team/list.ts`, correctly use the `escapeMarkdownCell` helper for similar
user-provided data.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

good catch — wrapped the author fallback chain with escapeMarkdownCell() in 56d4f35.

MathurAditya724 added a commit that referenced this pull request May 21, 2026
## Summary
- wraps the `author` column in `dashboard revisions` with
`escapeMarkdownCell()` to prevent markdown table breakage when a user's
name or email contains `|`
- missed in #1000 — caught by sentry[bot]'s automated review

One-line change, no new dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support dashboard revision history

1 participant