codeant-ai-for-open-source[bot] commented on code in PR #40817:
URL: https://github.com/apache/superset/pull/40817#discussion_r3409029522
##########
superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx:
##########
@@ -116,3 +116,19 @@ Handlebars.registerHelper('parseJson', (jsonString:
string) => {
Helpers.registerHelpers(Handlebars);
HandlebarsGroupBy.register(Handlebars);
+
+// `just-handlebars-helpers` registers a `formatDate` helper that lazily
+// resolves `moment` via `global.moment` /
`require('moment/min/moment-with-locales')`.
+// The bundled viewer switched to dayjs and never satisfies that lookup, so the
+// original helper throws "... is not a function" (see #32960). Re-register a
+// dayjs-backed `formatDate` with the same `{{formatDate formatString date
[locale]}}`
+// signature so existing templates keep rendering.
+Handlebars.registerHelper('formatDate', (formatString, date, localeString) => {
+ const format = typeof formatString === 'string' ? formatString : '';
+ const instance = dayjs(date || new Date());
Review Comment:
**Suggestion:** The fallback logic treats any falsy `date` as "missing" and
replaces it with `new Date()`, which breaks valid inputs like Unix epoch `0`
(or other falsy-but-valid date values). This will render the current date
instead of the requested value. Use a null/undefined-only fallback and preserve
legitimate falsy date inputs. [falsy zero check]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Handlebars charts misformat zero or epoch date fields.
- ⚠️ Users see current date instead of stored timestamps.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Create or select a dataset whose query returns a column with numeric
value 0 (Unix
epoch), then in the Explore UI choose the Handlebars visualization type,
which renders via
`Handlebars` in
`superset-frontend/plugins/plugin-chart-handlebars/src/Handlebars.tsx:32-47`
and passes
the raw query data into `HandlebarsViewer` as `{ data }`.
2. In the Handlebars chart controls, set `handlebarsTemplate` to use the
helper with a
zero-valued field, e.g. `{{formatDate 'YYYY-MM-DD' ts}}` where `ts` is the
column that
evaluates to 0; at runtime this template is compiled and executed by
`Handlebars.compile(templateSource)` in `HandlebarsViewer` at
`superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx:48-52`.
3. When the compiled template runs, the Handlebars runtime resolves
`{{formatDate
'YYYY-MM-DD' ts}}` to the helper registered in
`HandlebarsViewer.tsx:120-127`, invoking
`Handlebars.registerHelper('formatDate', (formatString, date, localeString)
=> { ... })`
with `formatString = 'YYYY-MM-DD'` and `date = 0` (plus the trailing options
object
described in the comment at lines 50–51).
4. Inside this helper, the line `const instance = dayjs(date || new
Date());` (line 128 in
the PR hunk) treats `date = 0` as falsy, so `date || new Date()` evaluates
to `new
Date()`, causing `dayjs` to format the current time instead of the Unix
epoch; the chart
then displays today's date instead of the stored zero timestamp,
demonstrating that
legitimate falsy date inputs are overwritten by `new Date()` rather than
preserved, which
would be fixed by checking only `null`/`undefined` (e.g. `date ?? new
Date()`).
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=12ca886d528446209a38ccd6640569af&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=12ca886d528446209a38ccd6640569af&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-handlebars/src/components/Handlebars/HandlebarsViewer.tsx
**Line:** 128:128
**Comment:**
*Falsy Zero Check: The fallback logic treats any falsy `date` as
"missing" and replaces it with `new Date()`, which breaks valid inputs like
Unix epoch `0` (or other falsy-but-valid date values). This will render the
current date instead of the requested value. Use a null/undefined-only fallback
and preserve legitimate falsy date inputs.
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%2F40817&comment_hash=1d52409f5c4db701b8247fd84318f806e174faf81bcf20ededf05d9dd5c9d450&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40817&comment_hash=1d52409f5c4db701b8247fd84318f806e174faf81bcf20ededf05d9dd5c9d450&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]