Repository navigation
fix(reports): respect CSV_EXPORT sep and decimal config in email reports - #38616
Conversation
Code Review Agent Run #c83433Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
| output_data = processed_result["queries"][0]["data"] | ||
| lines = output_data.strip().split("\n") | ||
| # Should have header + 2 data rows, with correct column parsing | ||
| assert len(lines) == 3 | ||
| # name and value should be separate columns, not merged into one | ||
| assert processed_result["queries"][0]["colnames"] == ["name", "value"] |
There was a problem hiding this comment.
Suggestion: This test does not actually verify that the configured delimiter/decimal are preserved in the generated CSV output, so it can pass even when email CSV exports are still emitted with default comma and dot formatting. Strengthen the assertions to validate the serialized CSV content and numeric typing of the parsed value column. [logic error]
Severity Level: Major ⚠️
- ❌ Scheduled CSV emails may ignore configured separator/decimal output.
- ⚠️ Current unit test misses CSV serialization regressions.| output_data = processed_result["queries"][0]["data"] | |
| lines = output_data.strip().split("\n") | |
| # Should have header + 2 data rows, with correct column parsing | |
| assert len(lines) == 3 | |
| # name and value should be separate columns, not merged into one | |
| assert processed_result["queries"][0]["colnames"] == ["name", "value"] | |
| output_data = processed_result["queries"][0]["data"] | |
| lines = output_data.strip().split("\n") | |
| # Should have header + 2 data rows, with correct column parsing | |
| assert len(lines) == 3 | |
| # name and value should be separate columns, not merged into one | |
| assert processed_result["queries"][0]["colnames"] == ["name", "value"] | |
| # value should be parsed as numeric using decimal="," config | |
| assert processed_result["queries"][0]["coltypes"] == [ | |
| GenericDataType.STRING, | |
| GenericDataType.NUMERIC, | |
| ] | |
| # serialized CSV should honor configured separator/decimal for email exports | |
| assert lines[0] == "name;value" | |
| assert "foo;1,5" in lines[1] | |
| assert "bar;2,0" in lines[2] |
Steps of Reproduction ✅
1. Configure a report with non-default CSV settings
(`CSV_EXPORT={"sep":";","decimal":","}`), then trigger scheduled CSV generation through
`ReportScheduleStateMachine._get_csv_data()` in
`superset/commands/report/execute.py:439-443`, which calls `ChartDataRestApi.get_data`
with `type=post_processed` at `execute.py:226-230`.
2. In chart response handling, `_send_chart_response()` applies post-processing when
`result_type == POST_PROCESSED` (`superset/charts/data/api.py:404-405`), invoking
`apply_client_processing()`.
3. In `apply_client_processing()`, CSV is parsed with configured `sep`/`decimal`
(`superset/charts/client_processing.py:348-356`) but serialized back using default
`processed_df.to_csv(...)` without config (`client_processing.py:397`), yielding comma/dot
formatted output.
4. Run the current unit test `test_apply_client_processing_csv_format_custom_delimiter`
(`tests/unit_tests/charts/test_client_processing.py:2794-2832`): it only asserts row count
and `colnames` (`2827-2832`), so it still passes even when output CSV formatting is wrong.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/charts/test_client_processing.py
**Line:** 2827:2832
**Comment:**
*Logic Error: This test does not actually verify that the configured delimiter/decimal are preserved in the generated CSV output, so it can pass even when email CSV exports are still emitted with default comma and dot formatting. Strengthen the assertions to validate the serialized CSV content and numeric typing of the parsed `value` column.
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.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #38616 +/- ##
==========================================
- Coverage 64.42% 64.41% -0.01%
==========================================
Files 2668 2668
Lines 147182 147185 +3
Branches 33947 33947
==========================================
- Hits 94821 94816 -5
- Misses 50646 50652 +6
- Partials 1715 1717 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…d CSV output The previous fix only passed sep and decimal to pd.read_csv() (parsing the input CSV), but to_csv() was still called with pandas defaults, so email report attachments were still serialized with ',' and '.' regardless of config. Pass the same sep and decimal values to to_csv() so the round-trip is complete: configured separator and decimal are preserved in the output CSV sent as email attachment. Also strengthen the test to assert that the output CSV uses the configured separator and decimal, not just that column names were parsed correctly. Addresses review feedback on apache#38616.
Code Review Agent Run #f1c406Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
There was a problem hiding this comment.
Pull request overview
Fixes scheduled CSV email report processing to respect CSV_EXPORT delimiter/decimal settings so pandas parses non-comma CSV correctly and avoids post-processing errors.
Changes:
- Pass configured
sep/decimaltopd.read_csv()when processing CSV results inapply_client_processing. - Emit processed CSV using the same
sep/decimalviaDataFrame.to_csv(). - Add a unit test covering semicolon-delimited CSV with comma decimals.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| superset/charts/client_processing.py | Reads CSV_EXPORT config and applies sep/decimal consistently for CSV read/write in report processing. |
| tests/unit_tests/charts/test_client_processing.py | Adds a regression test for custom delimiter/decimal behavior in apply_client_processing. |
You can also share your feedback on Copilot code review. Take the survey.
| processed_result = apply_client_processing(result, form_data) | ||
|
|
||
| output_data = processed_result["queries"][0]["data"] | ||
| lines = output_data.strip().split("\n") |
|
Up to you do to do this or not, but I would consider adding a test for |
|
Additional tests to consider:
|
sadpandajoe
left a comment
There was a problem hiding this comment.
Some suggestions but none are blockers, so going to approve.
Code Review Agent Run #802f2fActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
@nitishagar this is in good shape and the fix seems right, but it's gone stale: it's now conflicting with |
|
I'll see if I can help CI along here... |
|
The rebase proved non-trivial... the PR's read-side CSV sep/decimal fix is good for prod, but master rewrote the write side and added #32371's tests that FAIL with the PR applied. Resolving means making a data-format-model call and rewriting master's two new tests to feed config-formatted input. Feel free to take a look at this, if you'd like, or perhaps I can find time to make more significant edits if you'd like. |
Code Review Agent Run #376f8aActionable Suggestions - 0Additional Suggestions - 3
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
User description
SUMMARY
When
CSV_EXPORTconfig uses a non-default delimiter (e.g.sep=";") and decimal separator (e.g.decimal=","), GUI CSV exports work correctly because they go throughquery_context_processor.pywhich passes**current_app.config["CSV_EXPORT"]todf_to_escaped_csv(). However, CSV email reports take a different path throughapply_client_processing()inclient_processing.py, which calledpd.read_csv(StringIO(data))without readingsep/decimalfrom the config.This caused pandas to misparse the semicolon-delimited CSV (treating the whole row as one column), which then broke the pivot/table post-processor and returned an HTTP 500.
Fix: Read
sepanddecimalfromcurrent_app.config["CSV_EXPORT"]and pass them topd.read_csv(), defaulting to","and"."respectively when not configured.Fixes #36682
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only fix.
TESTING INSTRUCTIONS
CSV_EXPORT = {"sep": ";", "decimal": ","}insuperset_config.pyUnit test added:
ADDITIONAL INFORMATION
CodeAnt-AI Description
Respect CSV export settings in scheduled reports
What Changed
Impact
✅ Fewer failed CSV email reports✅ Correct parsing for semicolon-delimited exports✅ Clearer scheduled report output with custom decimal formats💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.