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


##########
superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts:
##########
@@ -227,7 +227,10 @@ export const buildQuery: BuildQuery<TableChartFormData> = (
         formData?.result_type === 'results');
 
     if (isDownloadQuery) {
-      moreProps.row_limit = Number(formDataCopy.row_limit) || 0;
+      moreProps.row_limit =
+        formDataCopy.row_limit != null
+          ? Number(formDataCopy.row_limit)
+          : undefined;

Review Comment:
   **Suggestion:** The new conversion only checks for null/undefined before 
calling `Number`, so non-numeric string values (for example legacy or 
URL-provided `row_limit`) become `NaN` here. That bypasses the normal 
`buildQueryObject` sanitization and injects an invalid `row_limit` into 
download queries, which can serialize differently from the display query and 
still miss cache (and may produce incorrect backend handling). Normalize 
invalid numeric values to `undefined` instead of passing through `NaN`. [cache]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ❌ Table chart CSV/XLSX exports may still miss cache.
   ⚠️ Malformed row_limit values yield inconsistent export query objects.
   ⚠️ Edge-case exports may ignore intended row limits.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In a unit test, import `buildQuery` from
   `superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts` (function 
defined around
   line 57) and call it with a `TableChartFormData` object where 
`result_format: 'csv'`,
   `result_type: 'results'`, and `row_limit: 'not-a-number'` (a non-numeric 
string), plus any
   valid datasource/metrics.
   
   2. During `buildQuery` execution, the callback passed to `buildQueryContext` 
computes
   `isDownloadQuery` (lines ~75–78) which evaluates to `true` for 
`result_format: 'csv'`,
   then enters the `if (isDownloadQuery)` block at line 229.
   
   3. Inside that block (lines 230–233) the code sets `moreProps.row_limit =
   formDataCopy.row_limit != null ? Number(formDataCopy.row_limit) : 
undefined;`. With
   `row_limit: 'not-a-number'`, `formDataCopy.row_limit != null` is `true`,
   `Number('not-a-number')` produces `NaN`, so the resulting query object in
   `buildQueryContext(...).queries[0]` has `row_limit` set to `NaN`.
   
   4. The same chart’s on-screen (display) query, built with identical form 
data but
   `result_format: 'json'` / non-download settings, does not pass through this
   `isDownloadQuery` block and instead uses the sanitized `row_limit` from the 
underlying
   `buildQueryContext`/`QueryObject` creation, so its `row_limit` is a valid 
integer or
   `undefined`, not `NaN`. Because the backend cache keys for SQLA datasets are 
derived by
   passing the query object into `get_sqla_query` with `SQLA_QUERY_KEYS` 
including
   `"row_limit"` (see `superset/connectors/sqla/models.py:2131–2137` and
   `superset/models/helpers.py:197–202` where `"row_limit"` is listed), the 
export query
   containing `row_limit: NaN` (serialized to `null`) produces a different 
cache key than the
   display query’s `row_limit` (valid int or omitted), so CSV/XLSX exports for 
such malformed
   `row_limit` values will bypass the populated cache and re-execute the query. 
Normalizing
   invalid numeric inputs to `undefined` here would keep export and display 
query shapes
   aligned and restore cache reuse.
   ```
   </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=8cee67f7e0f84e75a48a8a534f4b570b&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=8cee67f7e0f84e75a48a8a534f4b570b&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-frontend/plugins/plugin-chart-table/src/buildQuery.ts
   **Line:** 230:233
   **Comment:**
        *Cache: The new conversion only checks for null/undefined before 
calling `Number`, so non-numeric string values (for example legacy or 
URL-provided `row_limit`) become `NaN` here. That bypasses the normal 
`buildQueryObject` sanitization and injects an invalid `row_limit` into 
download queries, which can serialize differently from the display query and 
still miss cache (and may produce incorrect backend handling). Normalize 
invalid numeric values to `undefined` instead of passing through `NaN`.
   
   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%2F41469&comment_hash=ba6a9a295e4c72c32425f40dc591d6a7429d428d1478b90e67eb333f37289edf&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41469&comment_hash=ba6a9a295e4c72c32425f40dc591d6a7429d428d1478b90e67eb333f37289edf&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