You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "geido (via GitHub)" <gi...@apache.org> on 2026/04/21 15:25:49 UTC

[PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

geido opened a new pull request, #39525:
URL: https://github.com/apache/superset/pull/39525

   ### SUMMARY
   Fixes a race condition in `useDownloadScreenshot` where some users saw the dashboard screenshot (PDF/PNG) downloaded **twice** when triggered via the browser. The polling loop that waits for the generated screenshot had no in-flight guard, so interval ticks could stack concurrent GETs; when the image became ready, each in-flight request returned 200 and each triggered `a.click()`.
   
   **Why it started happening recently** — the polling logic was pre-existing, but #38880 (`fix(dashboard): Ensure screenshot downloads always generate fresh images/pdfs`) added `force=true` to the cache_dashboard_screenshot POST. Before, the backend could serve a cached screenshot immediately and no retries were needed. After, the async Celery task runs on every download, so the retry path is now the default, exposing the race on every request.
   
   **The fix** — two guards in `downloadScreenshot` (both local to one invocation):
   - `isFetching` — `fetchImageWithRetry` short-circuits while a GET is still pending, so interval ticks can't stack concurrent requests. Reset in `.finally`.
   - `isDownloaded` — the success `.then` bails if already downloaded, and sets the flag + calls `stopIntervals('success')` before `a.click()` so any late-arriving 200 can't fire a second download.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A — network-level behavior. Reported pattern: multiple 200 responses for `/screenshot/<cache_key>/?download_format=pdf` each triggering a browser download.
   
   ### TESTING INSTRUCTIONS
   Unit tests added in `useDownloadScreenshot.test.ts`:
   - `does not issue overlapping GETs while a previous GET is in-flight` — verifies the `isFetching` guard by advancing fake timers while the first GET is pending.
   - `triggers only one download when multiple successful responses race` — verifies only one `a.click()` fires even when subsequent responses resolve 200.
   
   Both tests fail against the current master behavior (click called 5× without the fix) and pass with the fix applied.
   
   ```
   cd superset-frontend
   npx jest src/dashboard/hooks/useDownloadScreenshot.test.ts
   ```
   
   Manual: open a large dashboard → Download → PDF/PNG. Confirm exactly one file is downloaded on slow-generation paths.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4289806818

   <!-- Bito Reply -->
   The PR only modifies the test file for the useDownloadScreenshot hook. It doesn't show usage of the hook elsewhere in the codebase.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4304233934

   🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/24834383241) for [90774c6](https://github.com/apache/superset/commit/90774c6)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4341793464

   🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/25096310312) for [90774c6](https://github.com/apache/superset/commit/90774c6)
   
   • **Environment:** http://35.89.182.34:8080 (admin/admin)
   • **Lifetime:** 48h auto-cleanup
   • **Updates:** New commits create fresh environments automatically


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4310893003

   🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/24873226695) for [90774c6](https://github.com/apache/superset/commit/90774c6)
   
   • **Environment:** http://16.146.144.3:8080 (admin/admin)
   • **Lifetime:** 48h auto-cleanup
   • **Updates:** New commits create fresh environments automatically


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4289889199

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/39525?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `92.85714%` with `1 line` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 64.50%. Comparing base ([`191337e`](https://app.codecov.io/gh/apache/superset/commit/191337e08d8b7cdd2c3fcba47cbfb023facfaabc?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`90774c6`](https://app.codecov.io/gh/apache/superset/commit/90774c68e3ba082d4d6f7e203930416bf389551d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 2 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/39525?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...ntend/src/dashboard/hooks/useDownloadScreenshot.ts](https://app.codecov.io/gh/apache/superset/pull/39525?src=pr&el=tree&filepath=superset-frontend%2Fsrc%2Fdashboard%2Fhooks%2FuseDownloadScreenshot.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2Rhc2hib2FyZC9ob29rcy91c2VEb3dubG9hZFNjcmVlbnNob3QudHM=) | 92.85% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #39525      +/-   ##
   ==========================================
   + Coverage   64.46%   64.50%   +0.04%     
   ==========================================
     Files        2559     2559              
     Lines      133564   133641      +77     
     Branches    31016    31049      +33     
   ==========================================
   + Hits        86097    86207     +110     
   + Misses      45974    45941      -33     
     Partials     1493     1493              
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/39525/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [javascript](https://app.codecov.io/gh/apache/superset/pull/39525/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.55% <92.85%> (+0.07%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/39525?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4304339918

   🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/24834383241) for [90774c6](https://github.com/apache/superset/commit/90774c6)
   
   • **Environment:** http://35.86.123.144:8080 (admin/admin)
   • **Lifetime:** 48h auto-cleanup
   • **Updates:** New commits create fresh environments automatically


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "EnxDev (via GitHub)" <gi...@apache.org>.
EnxDev commented on code in PR #39525:
URL: https://github.com/apache/superset/pull/39525#discussion_r3159257820


##########
superset-frontend/src/dashboard/hooks/useDownloadScreenshot.test.ts:
##########
@@ -51,13 +51,52 @@ jest.mock('src/utils/urlUtils', () => ({
   getDashboardUrlParams: jest.fn(() => []),
 }));
 
-test('downloadScreenshot calls API with force=true to ensure fresh screenshots', async () => {
-  const mockCacheKey = 'test-cache-key';
+const RETRY_INTERVAL = 3000;

Review Comment:
   we have the same declaration inside this file `superset/superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "michaelmorera-preset (via GitHub)" <gi...@apache.org>.
michaelmorera-preset commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4341906850

   The application is working as expected.
   
   ## Manual verification (end-to-end behavior)
   1. Open a large/slow-to-render dashboard.
   2. Click Download and choose PDF or PNG.
   
   ## Current result
   After the step 2:
   - The screenshot generation is slow enough to hit the polling/retry path.
   - The browser triggers exactly one file download.
   
   ## Evidence
   <img width="800" height="423" alt="Thebrowsertriggersexactlyonefiledownload" src="https://github.com/user-attachments/assets/b112c2cb-7d4d-4453-9f7a-9129908b4954" />
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "msyavuz (via GitHub)" <gi...@apache.org>.
msyavuz commented on code in PR #39525:
URL: https://github.com/apache/superset/pull/39525#discussion_r3118590264


##########
superset-frontend/src/dashboard/hooks/useDownloadScreenshot.test.ts:
##########
@@ -51,13 +51,52 @@ jest.mock('src/utils/urlUtils', () => ({
   getDashboardUrlParams: jest.fn(() => []),
 }));
 
-test('downloadScreenshot calls API with force=true to ensure fresh screenshots', async () => {
-  const mockCacheKey = 'test-cache-key';
+const RETRY_INTERVAL = 3000;

Review Comment:
   Do we have this somewhere else as well that we can use?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4310783232

   🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/24873226695) for [90774c6](https://github.com/apache/superset/commit/90774c6)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4341693161

   🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/25096310312) for [90774c6](https://github.com/apache/superset/commit/90774c6)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "geido (via GitHub)" <gi...@apache.org>.
geido merged PR #39525:
URL: https://github.com/apache/superset/pull/39525


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(dashboard): prevent duplicate screenshot downloads [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39525:
URL: https://github.com/apache/superset/pull/39525#issuecomment-4289761047

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org