codeant-ai-for-open-source[bot] commented on code in PR #42927:
URL: https://github.com/apache/superset/pull/42927#discussion_r3742393401
##########
superset/common/query_object.py:
##########
@@ -205,8 +206,66 @@ def is_str_or_adhoc(metric: Metric) -> bool:
def _set_post_processing(
self, post_processing: list[dict[str, Any] | None] | None
) -> None:
- post_processing = post_processing or []
- self.post_processing = [post_proc for post_proc in post_processing if
post_proc]
+ self.post_processing = [
+ self._drop_unsupported_options(post_proc)
+ for post_proc in post_processing or []
+ if post_proc
+ ]
+
+ @staticmethod
+ def _drop_unsupported_options(post_proc: dict[str, Any]) -> dict[str, Any]:
+ """
+ Drop options that the post-processing operation no longer accepts.
+
+ A chart's ``query_context`` is written when the chart is saved and is
+ never rewritten afterwards, while Explore rebuilds the query from
+ ``form_data`` at every render. A chart saved by an older version of
+ Superset can therefore reference an option that has since been removed
+ from the operation. ``exec_post_processing`` passes the stored options
+ as keyword arguments, so that option raises a bare ``TypeError`` on
+ every path that replays the stored ``query_context`` -- the chart data
+ endpoint, alerts and reports, thumbnails, CSV export -- while the same
+ chart still renders correctly in Explore.
+
+ Comparing against the signature avoids a hard-coded list of removed
+ option names, which would need extending at each release.
+ """
+ operation = post_proc.get("operation")
+ function = (
+ getattr(pandas_postprocessing, operation, None)
+ if isinstance(operation, str)
+ else None
+ )
+ if function is None:
+ # A missing or unknown operation is left untouched, so that
+ # exec_post_processing reports it as InvalidPostProcessingError.
+ return post_proc
+
+ parameters = inspect.signature(function).parameters
+ if any(
+ parameter.kind is inspect.Parameter.VAR_KEYWORD
+ for parameter in parameters.values()
+ ):
+ return post_proc
+
+ options = post_proc.get("options") or {}
+ unsupported = {key for key in options if key not in parameters}
Review Comment:
**Suggestion:** The parameter-name check treats `df` as a supported option,
but every post-processing function already receives the DataFrame as the first
positional argument. If stored options contain `df`, it survives filtering and
the later call `operation(df, **options)` raises `TypeError` because `df` is
supplied twice. Exclude the explicitly positional DataFrame parameter from
keyword options. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Chart data requests fail for queries containing a `df` option.
- ❌ Post-processing prevents affected results from being returned.
- ⚠️ The unrestricted options schema permits this malformed option.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=23b2c2ae96f04350a22280ea40b9cb24&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=23b2c2ae96f04350a22280ea40b9cb24&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/common/query_object.py
**Line:** 252:252
**Comment:**
*Type Error: The parameter-name check treats `df` as a supported
option, but every post-processing function already receives the DataFrame as
the first positional argument. If stored options contain `df`, it survives
filtering and the later call `operation(df, **options)` raises `TypeError`
because `df` is supplied twice. Exclude the explicitly positional DataFrame
parameter from keyword options.
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%2F42927&comment_hash=2d9cd77db0cdd03107cdcf56c12d2a84eb2d20c416c0a72f63d5864b3d94ea24&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42927&comment_hash=2d9cd77db0cdd03107cdcf56c12d2a84eb2d20c416c0a72f63d5864b3d94ea24&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]