codeant-ai-for-open-source[bot] commented on code in PR #40636:
URL: https://github.com/apache/superset/pull/40636#discussion_r3337846274
##########
superset/viz.py:
##########
@@ -633,7 +654,10 @@ def get_df_payload( # pylint: disable=too-many-statements
# noqa: C901
)
self.errors.append(error)
self.status = QueryStatus.FAILED
- stacktrace = utils.get_stacktrace()
+ # Only expose the raw stacktrace when explicitly enabled,
mirroring
+ # the gating used elsewhere (e.g.
superset.views.base.get_error_msg).
+ if current_app.debug or
current_app.config.get("SHOW_STACKTRACE"):
+ stacktrace = utils.get_stacktrace()
Review Comment:
**Suggestion:** The debug-path stacktrace gating is ineffective because
`utils.get_stacktrace()` only returns a value when `SHOW_STACKTRACE` is
enabled. When `current_app.debug` is true but `SHOW_STACKTRACE` is false, this
branch still returns `None`, so stacktraces are incorrectly hidden. Use
`traceback.format_exc()` for the debug branch (or update the helper to honor
debug mode) so the condition behaves as intended. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Debug-mode chart errors lack stacktraces in response payload.
- ⚠️ Inconsistent behavior with intended debug-or-config stacktrace gating.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Observe helper behavior in `superset/utils/core.py:1584-1589`, where
`get_stacktrace()`
only returns `traceback.format_exc()` when `app.config["SHOW_STACKTRACE"]`
is truthy and
otherwise returns `None`, ignoring Flask debug mode.
2. In `tests/unit_tests/test_viz_get_df_payload.py:36-51`, use the `_viz()`
helper to
construct a `viz.BaseViz` instance (with `force=True`) so that
`BaseViz.get_df_payload()`
in `superset/viz.py:557-683` is exercised.
3. In a test or shell context with an active Flask app, set
`current_app.debug = True` and
patch `current_app.config` so `SHOW_STACKTRACE` is `False` (mirroring the
pattern in
`test_get_df_payload_hides_stacktrace_when_show_stacktrace_disabled` at
`tests/unit_tests/test_viz_get_df_payload.py:173-191`).
4. Patch `viz.BaseViz.get_df` to raise `RuntimeError("boom")` (similar to
`test_get_df_payload_captures_generic_exception` at
`tests/unit_tests/test_viz_get_df_payload.py:136-151`) and call
`obj.get_df_payload(QUERY_OBJ)`; the generic exception handler at
`superset/viz.py:645-656` executes the gating condition at
`superset/viz.py:659-660`, but
`utils.get_stacktrace()` (bound to `superset.utils.core.get_stacktrace`)
returns `None`
because `SHOW_STACKTRACE` is `False`, so `payload["stacktrace"]` remains
`None` even
though `current_app.debug` is `True`, demonstrating the debug branch does
not actually
surface a stacktrace.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5b10b500428d43b69afc9f852e7022bb&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=5b10b500428d43b69afc9f852e7022bb&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/viz.py
**Line:** 659:660
**Comment:**
*Logic Error: The debug-path stacktrace gating is ineffective because
`utils.get_stacktrace()` only returns a value when `SHOW_STACKTRACE` is
enabled. When `current_app.debug` is true but `SHOW_STACKTRACE` is false, this
branch still returns `None`, so stacktraces are incorrectly hidden. Use
`traceback.format_exc()` for the debug branch (or update the helper to honor
debug mode) so the condition behaves as intended.
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%2F40636&comment_hash=623a135eb5c0e847c001316e9b64ea65fe902c0291938211f784ab02f724366c&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40636&comment_hash=623a135eb5c0e847c001316e9b64ea65fe902c0291938211f784ab02f724366c&reaction=dislike'>👎</a>
##########
superset/viz.py:
##########
@@ -1061,6 +1085,13 @@ def process_data(self, df: pd.DataFrame, aggregate: bool
= False) -> VizData:
method = self.form_data.get("resample_method")
if rule and method:
+ if method not in ALLOWED_RESAMPLE_METHODS:
+ raise QueryObjectValidationError(
+ _(
+ "Resample method '%(method)s' is not supported.",
+ method=method,
+ )
+ )
Review Comment:
**Suggestion:** The allowlist check assumes `resample_method` is hashable;
if a malformed request sends a non-hashable value (for example a list), `method
not in ALLOWED_RESAMPLE_METHODS` raises `TypeError` instead of the intended
`QueryObjectValidationError`. Validate that `method` is a string before
membership testing so unsupported input consistently returns a controlled
validation error. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Malformed resample_method crashes chart request with TypeError.
- ⚠️ Invalid resample methods return 500 instead of validation error.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. In `tests/unit_tests/test_viz_get_df_payload.py:54-69`, use the
`_timeseries_viz`
helper to construct a `viz.NVD3TimeSeriesViz` with form data that sets
`"resample_rule":
"1D"` and a non-hashable `"resample_method": ["mean"]` (a list instead of a
string).
2. Use `_resample_df()` from
`tests/unit_tests/test_viz_get_df_payload.py:72-84` to create
a DataFrame with a `DTTM_ALIAS` datetime index and a numeric `value` column,
matching the
expectations of `NVD3TimeSeriesViz.process_data` in
`superset/viz.py:1064-1107`.
3. Call `obj.process_data(_resample_df())`; execution enters
`NVD3TimeSeriesViz.process_data` at `superset/viz.py:1064`, computes the
pivot, then reads
`rule` and `method` from `self.form_data` at `superset/viz.py:1084-1085`, so
`rule` is
`"1D"` and `method` is the list `["mean"]`.
4. The branch `if rule and method:` at `superset/viz.py:1087` evaluates to
true, and the
membership test `if method not in ALLOWED_RESAMPLE_METHODS:` at
`superset/viz.py:1088-1094` attempts to hash `method` (a list) for lookup in
the
`frozenset` `ALLOWED_RESAMPLE_METHODS`, raising `TypeError: unhashable type:
'list'`
instead of the intended `QueryObjectValidationError`, causing a runtime
failure for
malformed `resample_method` inputs.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0b84cf2a365f4ce0ad92f0d43a369d70&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=0b84cf2a365f4ce0ad92f0d43a369d70&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/viz.py
**Line:** 1088:1094
**Comment:**
*Type Error: The allowlist check assumes `resample_method` is hashable;
if a malformed request sends a non-hashable value (for example a list), `method
not in ALLOWED_RESAMPLE_METHODS` raises `TypeError` instead of the intended
`QueryObjectValidationError`. Validate that `method` is a string before
membership testing so unsupported input consistently returns a controlled
validation error.
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%2F40636&comment_hash=d6085fbf6ab2790da95c43ce72cf52b2fd30cb121fd5b7aaa2c86a1fa566432d&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40636&comment_hash=d6085fbf6ab2790da95c43ce72cf52b2fd30cb121fd5b7aaa2c86a1fa566432d&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]