Skip to content

fix(dashboards): read the dashboard's widgets when GET /widgets fails - #235

Open
Severin Neumann (svrnm) wants to merge 1 commit into
mainfrom
fix/dashboards-widgets-list-fallback
Open

Severin Neumann (svrnm) wants to merge 1 commit into
mainfrom
fix/dashboards-widgets-list-fallback

Conversation

@svrnm

Copy link
Copy Markdown
Contributor

Closes #222.

dashboards apply (and --dry-run) and dashboards export share fetchWidgetsAndDefs, which lists every widget in the org. Live, that list can return 500 because of one broken widget elsewhere in the org (#111, and again in #222). All three commands then failed before doing anything.

Now, when GET /widgets returns a 5xx, fetchWidgetsAndDefs reads the dashboard's widget_ids one at a time through GET /widgets/{id} (a new dashboard has none) and prints a note on stderr. Other errors (401, 403, network) still fail as they did before. If the fallback fails too, the original error is reported.

Trade-off, which the code comment also states: while in fallback mode, apply can't see widgets it owns that were detached from the dashboard, so it leaves them alone instead of deleting them.

Test: TestWidgetListFailureFallsBackToDashboardWidgets adds a listErr switch to the fakeOrg test server. It applies a manifest, makes the list return 500, then checks that a re-apply makes zero writes and prints the note, and that export still writes the widgets.

The percentile-with-group_by 500 mentioned at the end of #222 is a server-side issue and is not covered here.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 11, 2026 06:44

Copilot AI 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.

🟡 Changes recommended

The fallback treats an attached-only widget inventory as complete, risking deletion of detached or shared definitions and failing to resolve valid references to unattached widgets.

2 open issues
What changed in this PR

Adds a fallback for dashboard apply, dry-run, and export when the org-wide widget list returns a server error, addressing the failure reported in #222.

Changes:

  • Fetches attached widgets individually after a widget-list 5xx and prints a fallback notice.
  • Preserves existing handling for other errors and returns the original error if fallback fails.
  • Adds fake-server failure injection and regression coverage for re-apply and export.
File Description
internal/​cli/​dashlive.go Implements dashboard-scoped widget fetching after list server errors.
internal/​cli/​dashfake_test.go Adds a switch to simulate widget-list failures.
internal/​cli/​dashapply_test.go Tests no-write re-apply, fallback notice, and export during list failures.

Review effort: Balanced

Comment thread internal/cli/dashlive.go
// a broken widget elsewhere in the org. Apply and export only need
// this dashboard's widgets. The cost: apply can't see widgets it
// owns that were detached from the dashboard, so it leaves them be.
if fbErr := fetchDashboardWidgets(ctx, app, st); fbErr != nil {
Comment thread internal/cli/dashlive.go
Comment on lines +154 to +157
if st.Dashboard == nil {
return nil
}
for _, row := range rowsFromPayload(payload, "widgets") {
for _, id := range st.Dashboard.WidgetIDs {
apply, apply --dry-run and export all list every widget in the org
first. When that list answers 5xx (a broken widget elsewhere in the
org, #111 and again #222), fetchWidgetsAndDefs now reads the
dashboard's attached widgets one by one via GET /widgets/{id} and
prints a note. Widgets the dashboard owns but that were detached from
it are invisible in this mode, so apply leaves them alone.

Closes #222.

Assisted-By: Claude

This branch was successfully deployed

1 active deployment
bronto-it — 82a34a93 Deployed Nov 11, 2026 by svrnm via integration #446
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.

dashboards apply/export fail when GET /widgets returns 500 again (org-specific, template-derived dashboard); fall back to the dashboard's widgets

2 participants