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


##########
superset-frontend/src/components/Chart/DrillDetail/DrillDetailModal.tsx:
##########
@@ -117,6 +174,73 @@ export default function DrillDetailModal({
     history.push(exploreUrl);
   }, [exploreUrl, history]);
 
+  const handleDownload = useCallback(
+    (exportType: 'csv' | 'xlsx') => {
+      const drillPayload = getDrillPayload(formData, initialFilters);
+
+      if (!drillPayload) {
+        dispatch(addDangerToast(t('Unable to generate download payload')));
+        return;
+      }
+
+      if (!formData.datasource || typeof formData.datasource !== 'string') {
+        dispatch(addDangerToast(t('Invalid datasource configuration')));
+        return;
+      }
+
+      const datasourceParts = formData.datasource.split('__');
+      if (datasourceParts.length !== 2) {
+        dispatch(addDangerToast(t('Invalid datasource format')));
+        return;
+      }
+
+      const [datasourceId, datasourceType] = datasourceParts;

Review Comment:
   **Suggestion:** The datasource string is destructured in the wrong order: 
the code assumes the first part is the numeric id and the second is the type, 
but Superset datasource strings are commonly "type__id" (type first, id 
second). As written, parseInt will be called on the type (e.g. "table") 
producing NaN and an invalid datasource id being sent to the backend. Swap the 
destructuring order so the id is parsed correctly. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Drill detail exports fail with invalid datasource id.
   - ⚠️ Users see export failure danger toast.
   - ⚠️ Affects Download (CSV/XLSX) in drill modal.
   - ⚠️ Calls to /api/v1/chart/data send wrong id.
   ```
   </details>
   
   ```suggestion
         const [datasourceType, datasourceId] = datasourceParts;
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open the Drill to detail modal and click the download button (footer 
button with
   data-test `drill-detail-download-btn` rendered from
   superset-frontend/src/components/Chart/DrillDetail/DrillDetailModal.tsx). 
The Dropdown
   selection handler is defined in ModalFooter (menu.onClick) which calls
   onDownloadCSV/onDownloadXLSX (ModalFooter code around lines ~80-116).
   
   2. The ModalFooter prop onDownloadCSV maps to handleDownloadCSV defined in
   DrillDetailModal.tsx at approximately lines 236-238 which calls 
handleDownload('csv').
   
   3. handleDownload is defined in DrillDetailModal.tsx at approximately lines 
177-234.
   Inside it the code splits the datasource string at line 191: const 
datasourceParts =
   formData.datasource.split('__'); and then destructures: const [datasourceId,
   datasourceType] = datasourceParts; (line 197).
   
   4. On a typical Superset datasource string (e.g., "table__123"), the current 
destructuring
   treats "table" as datasourceId. parseInt(datasourceId, 10) (later at line 
~203) will
   produce NaN and the constructed payload will send an invalid id to the 
backend, causing
   the export request to fail or return an error (user sees the danger toast 
added at lines
   ~182 and ~227). This reproduces the issue when clicking Export → CSV/Excel 
for charts
   whose formData.datasource follows the common "type__id" format.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/components/Chart/DrillDetail/DrillDetailModal.tsx
   **Line:** 197:197
   **Comment:**
        *Type Error: The datasource string is destructured in the wrong order: 
the code assumes the first part is the numeric id and the second is the type, 
but Superset datasource strings are commonly "type__id" (type first, id 
second). As written, parseInt will be called on the type (e.g. "table") 
producing NaN and an invalid datasource id being sent to the backend. Swap the 
destructuring order so the id is parsed correctly.
   
   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.
   ```
   </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: [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