Skip to content

fix(reports): open existing subscription instead of failing on duplicate - #45753

Open
BrandanBurgess wants to merge 5 commits into
apache:masterfrom
BrandanBurgess:fix/report-duplicate-subscription-redirect
Open

BrandanBurgess wants to merge 5 commits into
apache:masterfrom
BrandanBurgess:fix/report-duplicate-subscription-redirect

Conversation

@BrandanBurgess

Copy link
Copy Markdown
Contributor

SUMMARY

When a user tries to set up an email report for a chart or dashboard they are already subscribed to, POST /api/v1/report/subscribe returns 409 Resource already has an attached report. The report modal treated that like any other failure: a "Failed to create report" toast plus an error alert, leaving the user to find their existing subscription on the Alerts & Reports page.

This usually happens when the header menu is out of date, e.g. the subscription was created in another tab, so the menu still offers "Set up an email report" instead of "Manage email report".

With this change, a 409 on the subscribe path:

  • no longer raises the "Failed to create report" danger toast in subscribeReport
  • re-fetches the user's report for that chart or dashboard (the same fetchUISpecificReport lookup the header dropdown uses), which puts it in the Redux store, so the modal switches to edit mode with the existing report's settings and the header menu updates to "Manage email report"
  • shows an info toast explaining that the existing report was opened for editing

If the existing report can't be found (for example, the lookup fails), the modal falls back to the current error behaviour.

No backend change is needed: the 409 is already returned and covered by tests/integration_tests/reports/api_tests.py.

Based on the discussion in #42922.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before: "Failed to create report" toast and error alert in the modal.
After: the modal reopens as "Edit email report" with the existing subscription loaded, plus an info toast.

TESTING INSTRUCTIONS

  1. Enable ALERT_REPORTS and open a dashboard in two tabs.
  2. In tab 1, choose "Set up an email report" and save.
  3. In tab 2 (menu still shows "Set up an email report"), set one up again and click Add.
  4. The modal switches to "Edit email report" with the existing report's settings, an info toast explains why, and no failure toast is shown.

Unit tests: npm run test -- src/features/reports/ReportModal

  • duplicate subscription opens the existing report for editing
  • duplicate subscription shows the error when the existing report cannot be found

ADDITIONAL INFORMATION

🤖 Generated with Claude Code

Subscribing to a chart or dashboard the user already has a report for
returns a 409 from /api/v1/report/subscribe. The report modal showed a
generic "Failed to create report" error. On a 409 it now loads the
existing subscription into the modal in edit mode and explains why.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: fe5e2e68cb6e

@gabotorresruiz gabotorresruiz 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.

@BrandanBurgess thanks for picking this up from the discussion in #42922, nice fix! The duplicate path checks out for both charts and dashboards. I left one small non-blocking note inline.

CI note: the failing lanes are infrastructure (mostly a GitHub API rate limit during change detection), and because of that the frontend test and lint lanes were skipped. I ran the src/features/reports/ suites locally and they pass.

'You are already subscribed to this dashboard. Your existing report has been opened for editing.',
),
);
setCurrentReport({ isSubmitting: false });

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.

Not a blocker. The list endpoint behind fetchUISpecificReport doesn't return custom_width, so after this recovery the Screenshot width field keeps whatever was typed into the abandoned create form while every other field shows the existing report. Clicking Save then PUTs that width onto the existing subscription. Clearing it here keeps it out of the PUT, the same as opening the report from "Manage email report":

Suggested change
setCurrentReport({ isSubmitting: false });
setCurrentReport({ isSubmitting: false, custom_width: undefined });

Typing a width before clicking Add in your first test would pin it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'm going to make this change as well!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pushed changes to address this

The report list endpoint does not return custom_width, so after recovering
from a duplicate subscription the Screenshot width field kept the value typed
into the abandoned create form, and saving would PUT it onto the existing
report. Clear it, matching what opening via "Manage email report" does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.70%. Comparing base (492494b) to head (9e26990).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #45753      +/-   ##
==========================================
- Coverage   84.70%   84.70%   -0.01%     
==========================================
  Files        3069     3069              
  Lines      205610   205623      +13     
  Branches    48330    48338       +8     
==========================================
+ Hits       174157   174167      +10     
- Misses      28160    28163       +3     
  Partials     3293     3293              
Flag Coverage Δ
javascript 80.93% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants