Skip to content

fix(charts): use chart name in CSV/XLSX/zip export filenames#42193

Open
rusackas wants to merge 2 commits into
masterfrom
fix/issue-37487-chart-export-filename
Open

fix(charts): use chart name in CSV/XLSX/zip export filenames#42193
rusackas wants to merge 2 commits into
masterfrom
fix/issue-37487-chart-export-filename

Conversation

@rusackas

Copy link
Copy Markdown
Member

SUMMARY

Chart data exports (CSV/XLSX/zip) from /api/v1/chart/data were always
named with a bare timestamp (e.g. 20260127_160233.csv), even though the
endpoint already extracts a sanitized filename from the request. Only
the large-dataset streaming CSV path honored that filename (and its
chart-name-based fallback); the regular non-streaming CSV, XLSX, and
multi-query zip branches in _send_chart_response called
generate_download_headers() with no filename at all, dropping it on the
floor.

This PR:

  • Passes the extracted filename through to generate_download_headers()
    in the CSV, XLSX, and zip branches.
  • When no filename is supplied, falls back to the same chart-name +
    timestamp default already used by the streaming CSV path (extracted into
    a shared _get_default_export_filename helper to avoid duplicating that
    logic).
  • Report/email attachments already use the report name, so this change is
    scoped to the chart data export endpoints only.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (backend header change only)

TESTING INSTRUCTIONS

  1. Open any saved chart in Explore.
  2. Use Download → Export to CSV (or Excel).
  3. Confirm the downloaded filename starts with the chart's name instead of
    just a timestamp.

Also see the added unit tests in
tests/unit_tests/charts/test_chart_data_api.py, which pin the bug by
asserting the Content-Disposition header contains the chart name for
the CSV, XLSX, and zip export branches.

ADDITIONAL INFORMATION

  • Has associated issue: Fixes Exported file name is coming as a random string . #37487
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • 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

…rt headers

The /data endpoint already extracts a sanitized filename (falling back to
a chart-name-based default) for the streaming CSV export path, but the
non-streaming CSV, XLSX, and multi-query zip branches of
_send_chart_response ignored it and always called
generate_download_headers() with no filename, producing generic
timestamp-only download names.

Fixes #37487
@dosubot dosubot Bot added api:charts Related to the REST endpoints of charts viz:charts:export Related to exporting charts labels Jul 18, 2026
@github-actions github-actions Bot added the api Related to the REST API label Jul 18, 2026
@bito-code-review

bito-code-review Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b012f0

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: b4788d2..b4788d2
    • superset/charts/data/api.py
    • tests/unit_tests/charts/test_chart_data_api.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.08%. Comparing base (f6acf68) to head (2f57602).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
superset/charts/data/api.py 20.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42193      +/-   ##
==========================================
- Coverage   65.08%   65.08%   -0.01%     
==========================================
  Files        2758     2758              
  Lines      155229   155235       +6     
  Branches    35572    35572              
==========================================
+ Hits       101026   101029       +3     
- Misses      52288    52291       +3     
  Partials     1915     1915              
Flag Coverage Δ
hive 38.94% <20.00%> (+<0.01%) ⬆️
mysql 57.62% <20.00%> (-0.01%) ⬇️
postgres 57.68% <20.00%> (-0.01%) ⬇️
presto 40.90% <20.00%> (+<0.01%) ⬆️
python 59.10% <20.00%> (-0.01%) ⬇️
sqlite 57.29% <20.00%> (-0.01%) ⬇️
unit 100.00% <ø> (ø)

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.

Comment thread superset/charts/data/api.py
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. When a user provides a filename with an extension (e.g., my_export.csv), generate_download_headers appends the format extension again, resulting in double extensions like my_export.csv.csv.

To resolve this, you should strip the extension from the provided export_filename before passing it to generate_download_headers. You can use os.path.splitext for this purpose.

Proposed Fix

In superset/charts/data/api.py, update the _send_chart_response method to normalize the filename:

import os

# ... inside _send_chart_response ...
export_filename = filename or self._get_default_export_filename(form_data)
base_filename = os.path.splitext(export_filename)[0]

if is_csv_format:
    return CsvResponse(
        data, headers=generate_download_headers("csv", base_filename)
    )

Since there are no other comments in the provided PR context, there are no additional issues to address.

superset/charts/data/api.py

import os

# ... inside _send_chart_response ...
export_filename = filename or self._get_default_export_filename(form_data)
base_filename = os.path.splitext(export_filename)[0]

if is_csv_format:
    return CsvResponse(
        data, headers=generate_download_headers("csv", base_filename)
    )

…lename

The non-streaming CSV/XLSX/zip branch of _send_chart_response passed a
client-supplied filename straight into generate_download_headers(), which
always appends the format extension, producing doubled extensions like
"export.csv.csv" whenever the caller's filename already ends in
.csv/.xlsx/.zip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@netlify

netlify Bot commented Jul 18, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 2f57602
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a5b8aa39ce8b70008373b27
😎 Deploy Preview https://deploy-preview-42193--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #809fb6

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/charts/data/api.py - 1
    • Missing regression tests for xlsx/zip · Line 497-508
      The new regex stripping logic on lines 503–505 correctly prevents `chart.csv.csv` for CSV, but lacks an equivalent regression test for xlsx and zip paths at lines 515–516 and 535. A missing test allows a future refactor to silently reintroduce the doubled-extension bug on those formats.
Review Details
  • Files reviewed - 2 · Commit Range: b4788d2..2f57602
    • superset/charts/data/api.py
    • tests/unit_tests/charts/test_chart_data_api.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

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

Labels

api:charts Related to the REST endpoints of charts api Related to the REST API size/L viz:charts:export Related to exporting charts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exported file name is coming as a random string .

1 participant