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


##########
superset-frontend/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts:
##########
@@ -86,7 +91,7 @@ class CurrencyFormatter extends ExtensibleFunction {
     );
     this.d3Format = config.d3Format || NumberFormats.SMART_NUMBER;
     this.currency = config.currency;
-    this.locale = config.locale || 'en-US';
+    this.locale = config.locale || getCurrencyLocale();

Review Comment:
   **Suggestion:** The per-instance `locale` is used directly without 
canonicalization, so underscore-style tags (for example `pt_BR` / `zh_TW`) will 
make `Intl.NumberFormat` throw inside symbol-position resolution and silently 
fall back to `prefix`, producing incorrect symbol placement for locales that 
should use suffix. Canonicalize `config.locale` to a BCP-47 tag (same 
normalization used by `setCurrencyLocale`) before storing it on the formatter. 
[logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Per-instance locale overrides misplace symbols for underscore locales.
   - ⚠️ Charts using manual locale override lose suffix conventions.
   - ⚠️ Global and per-instance currency locales behave inconsistently.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Note that Superset bootstrap can emit underscore-formatted locales like 
`pt_BR` (see
   `/workspace/superset/superset-frontend/src/preamble.test.ts:99-104`, where
   `bootstrapData('pt_BR')` is passed through to `setupFormatters`).
   
   2. In any consumer of `@superset-ui/core`, construct a `CurrencyFormatter` 
with an
   underscore-style locale override, e.g. `new CurrencyFormatter({ currency: { 
symbol: 'EUR'
   }, d3Format: ',.2f', locale: 'fr_FR' })`, which is allowed by the
   `CurrencyFormatterConfig` type in
   
`/workspace/superset/superset-frontend/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts:33-37`.
   
   3. When `CurrencyFormatter.format()` runs (implementation at
   
`/workspace/superset/superset-frontend/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts:109-166`),
   it calls `resolveSymbolPosition(normalizedCurrency, 
this.currency.symbolPosition,
   this.locale)` in AUTO mode (lines 123-137) or 
`resolveSymbolPosition(this.currency.symbol,
   this.currency.symbolPosition, this.locale)` in static mode (lines 152-161), 
passing the
   raw `'fr_FR'` string stored at line 94 unchanged into the `locale` parameter.
   
   4. Inside `resolveSymbolPosition`
   
(`/workspace/superset/superset-frontend/packages/superset-ui-core/src/currency-format/symbolPosition.ts:47-81`),
   `new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode 
})` at line 63
   receives the non-BCP-47 tag `'fr_FR'`, which causes `Intl.NumberFormat` to 
throw a
   `RangeError`; this is caught at line 76 and the function falls back to 
returning
   `'prefix'` at line 81. This contradicts the intended behavior for French, 
where
   `setCurrencyLocale('fr-FR')` plus `resolveSymbolPosition('EUR')` correctly 
yields
   `'suffix'` (as asserted in
   
`/workspace/superset/superset-frontend/packages/superset-ui-core/test/currency-format/currencyLocale.test.ts:35-40`),
   so any `CurrencyFormatter` instance using an underscore-formatted locale 
override will
   silently get the wrong default symbol placement.
   ```
   </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=4be5aa3898374784917a0d1eefd4441c&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=4be5aa3898374784917a0d1eefd4441c&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/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts
   **Line:** 94:94
   **Comment:**
        *Logic Error: The per-instance `locale` is used directly without 
canonicalization, so underscore-style tags (for example `pt_BR` / `zh_TW`) will 
make `Intl.NumberFormat` throw inside symbol-position resolution and silently 
fall back to `prefix`, producing incorrect symbol placement for locales that 
should use suffix. Canonicalize `config.locale` to a BCP-47 tag (same 
normalization used by `setCurrencyLocale`) before storing it on the formatter.
   
   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%2F40931&comment_hash=07432a7468623df5405bd7e66c66c81589a3385b10de37188ab86c1956f528a9&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40931&comment_hash=07432a7468623df5405bd7e66c66c81589a3385b10de37188ab86c1956f528a9&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