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

   ### SUMMARY
   
   Exporting to Excel fails with a 500 and `'DataFrame' object has no attribute 
'dtype'` whenever the result set contains duplicate column labels. CSV export 
of the same data works.
   
   `apply_column_types` and `quote_formulas` in `superset/utils/excel.py` 
addressed columns by label. Under duplicate labels `df[label]` returns a 
DataFrame rather than a Series, so:
   
   - `apply_column_types` called `.dtype` on a DataFrame and raised.
   - `quote_formulas` passed whole columns to its mapper instead of individual 
cells, so `isinstance(x, str)` was `False` and formula escaping was silently 
skipped — no crash, just unquoted formulas.
   
   Duplicates arise because the `verbose_map` rename in 
`QueryContextProcessor.get_data` is not injective: two columns can share a 
verbose name. Drill to detail hits this readily because `_get_drill_detail` 
selects every column on the dataset, so one collision among them is enough. 
Only the XLSX branch calls `apply_column_types`, hence CSV being unaffected.
   
   Both functions now address columns by position via `df.iloc[:, idx]` and 
write back with `df.isetitem`, which is unambiguous under duplicate labels and 
avoids the in-place dtype casting that `iloc` assignment attempts. Duplicate 
headers are preserved in the output, matching what CSV export already does, so 
the two formats stay consistent.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A
   
   ### TESTING INSTRUCTIONS
   
   Two unit tests in `tests/unit_tests/utils/excel_tests.py` cover a frame with 
duplicate labels — one per bug. Both fail without this change (the first with 
the exact production error) and pass with it:
   
   ```
   pytest tests/unit_tests/utils/excel_tests.py
   ```
   
   Manually:
   
   1. Pick a dataset where two columns share a `verbose_name`, or add one via 
**Edit dataset → Columns → Label**.
   2. Build a chart on it, open the context menu → **Drill to detail**.
   3. **Export to Excel.** Without this change the download fails with a 500; 
with it the file downloads, both columns present under the shared header.
   4. **Export to CSV** as well, to confirm it is unchanged.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] 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: [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