codeant-ai-for-open-source[bot] commented on code in PR #42193:
URL: https://github.com/apache/superset/pull/42193#discussion_r3607947519


##########
superset/charts/data/api.py:
##########
@@ -495,13 +495,19 @@ def _send_chart_response(  # noqa: C901
                     result, form_data, filename=filename, 
expected_rows=expected_rows
                 )
 
+            export_filename = filename or 
self._get_default_export_filename(form_data)

Review Comment:
   **Suggestion:** `filename` can already include an extension (for example, 
`my_export.csv`), but it is passed directly as `export_filename` into 
`generate_download_headers`, which also appends the format extension; this 
produces duplicated names like `.csv.csv`/`.xlsx.xlsx` in downloads. Normalize 
the provided filename to a base name (or strip a matching trailing extension) 
before calling `generate_download_headers`. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ CSV exports with client-specified names show double extensions.
   - ⚠️ Affects /api/v1/chart/data non-streaming CSV responses.
   - ⚠️ Third-party clients using filename param get confusing filenames.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Call the chart data export endpoint `GET /api/v1/chart/data` (implemented 
in
   `superset/charts/data/api.py` in the `ChartDataRestApi` class) with
   `result_format=ChartDataResultFormat.CSV` and a single query, and include a 
`filename`
   parameter such as `filename=my_export.csv` so that `_send_chart_response` 
receives a
   non-empty `filename` argument.
   
   2. In `_send_chart_response` at `superset/charts/data/api.py:490-506`, the 
CSV path skips
   streaming because `_should_use_streaming(result, form_data)` at lines 
493-496 returns
   `False` for normal-sized datasets, and line 498 sets `export_filename = 
filename or
   self._get_default_export_filename(form_data)`, so `export_filename` is the 
literal string
   `my_export.csv` including the `.csv` extension.
   
   3. Still in `_send_chart_response`, for a single-query CSV result, the 
branch at lines
   500-506 executes `return CsvResponse(data, 
headers=generate_download_headers("csv",
   export_filename))`, passing `"csv"` as the format and `"my_export.csv"` as 
the
   `export_filename` argument into `generate_download_headers`.
   
   4. In `generate_download_headers` (defined in `superset/utils/core.py`, 
which constructs
   the `Content-Disposition` header by appending the format extension to the 
provided
   filename), the header becomes `attachment; filename="my_export.csv.csv"`, so 
the browser
   downloads a file named `my_export.csv.csv` instead of `my_export.csv`, 
demonstrating the
   duplicated extension whenever the client supplies a filename that already 
includes the
   extension.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=55c4b648db0b47519e1dad3e6354b6cf&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=55c4b648db0b47519e1dad3e6354b6cf&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/charts/data/api.py
   **Line:** 498:498
   **Comment:**
        *Logic Error: `filename` can already include an extension (for example, 
`my_export.csv`), but it is passed directly as `export_filename` into 
`generate_download_headers`, which also appends the format extension; this 
produces duplicated names like `.csv.csv`/`.xlsx.xlsx` in downloads. Normalize 
the provided filename to a base name (or strip a matching trailing extension) 
before calling `generate_download_headers`.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42193&comment_hash=7742c6a61740580ac0b44f79b81bf6ee39bace11e39afbae8b908aa358685077&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42193&comment_hash=7742c6a61740580ac0b44f79b81bf6ee39bace11e39afbae8b908aa358685077&reaction=dislike'>👎</a>



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to