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


##########
superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/transformProps.ts:
##########
@@ -79,8 +79,13 @@ export default function transformProps(
   const formattedSubtitleFontSize = subtitle?.trim()
     ? (subtitleFontSize ?? PROPORTION.SUBHEADER)
     : (subheaderFontSize ?? subtitleFontSize ?? PROPORTION.SUBHEADER);
+  const rawValue = data.length === 0 ? null : data[0][metricName];
+  const parsedValue = rawValue == null ? null : parseMetricValue(rawValue);
+  // Preserve non-date strings for display-only path
   const bigNumber =
-    data.length === 0 ? null : parseMetricValue(data[0][metricName]);
+    parsedValue === null && typeof rawValue === 'string' && rawValue !== ''
+      ? rawValue
+      : parsedValue;

Review Comment:
   **Suggestion:** The new fallback passes any non-empty string through as 
`bigNumber`, including numeric-looking VARCHAR values (for example `"123"`). 
Downstream rendering coerces string values with `Number(...)`, and because 
string columns use the time formatter, those values can be displayed as epoch 
dates instead of the original text. Restrict this fallback to truly non-numeric 
strings (or propagate a flag/type that prevents numeric coercion in rendering) 
so VARCHAR metrics like `"123"` are rendered literally. [incorrect condition 
logic]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Big-number-total chart misformats numeric VARCHAR metrics as timestamps.
   - ⚠️ KPI dashboards show misleading values for affected VARCHAR metrics.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Create a Big Number Total chart of type `big-number-total` (plugin 
registered in
   
`superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/index.ts:28-39`),
   using a dataset where the metric is `MAX(varchar_column)` and the backend 
reports the
   metric column as `GenericDataType.String` in `queriesData[0].coltypes[0]`.
   
   2. Ensure the first row of query results has a numeric-looking VARCHAR value 
such as
   `"123"` for the selected metric, so `queriesData[0].data[0][metricName] === 
'123'` and
   `coltypes[0] === GenericDataType.String` when `transformProps` runs
   (`transformProps.ts:69-82`).
   
   3. In `transformProps` (`transformProps.ts:82-88`), `rawValue` is set to 
`'123'` and
   `parsedValue = parseMetricValue(rawValue)` calls `parseMetricValue` from
   
`superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/utils.ts:34-42`, 
which tries
   `dayjs.utc('123', undefined, true)`; since `"123"` is not a valid strict 
date,
   `parseMetricValue` returns `null`, causing `bigNumber` to be set to the raw 
string `"123"`
   by the condition at lines 86-88.
   
   4. `BigNumberTotalChartPlugin` passes this `bigNumber` into `BigNumberViz` 
via
   `BigNumberVizProps` (`BigNumberTotal/index.ts:28-39`, 
`BigNumber/types.ts:23-30`), and in
   `BigNumberViz.tsx:184-198` the `renderHeader` function sees a non-null, 
non-number
   `bigNumber`, computes `numValue = Number(bigNumber)` → `123`, and, because 
`coltypes[0]
   === GenericDataType.String`, `headerFormatter` has been set to `formatTime` 
in
   `transformProps.ts:115-120`; `formatTime(123)` then formats `123` as a 
timestamp, so the
   Big Number chart displays a date/time instead of the literal `"123"`.
   ```
   </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=695e1b48fbac4a5bbb640f100350f891&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=695e1b48fbac4a5bbb640f100350f891&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-echarts/src/BigNumber/BigNumberTotal/transformProps.ts
   **Line:** 86:88
   **Comment:**
        *Incorrect Condition Logic: The new fallback passes any non-empty 
string through as `bigNumber`, including numeric-looking VARCHAR values (for 
example `"123"`). Downstream rendering coerces string values with 
`Number(...)`, and because string columns use the time formatter, those values 
can be displayed as epoch dates instead of the original text. Restrict this 
fallback to truly non-numeric strings (or propagate a flag/type that prevents 
numeric coercion in rendering) so VARCHAR metrics like `"123"` are rendered 
literally.
   
   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%2F41182&comment_hash=4c93fea04f9fc845a2e5a1de217052cf57acce5733f8b3322db3ba73b3d6f493&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41182&comment_hash=4c93fea04f9fc845a2e5a1de217052cf57acce5733f8b3322db3ba73b3d6f493&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