codeant-ai-for-open-source[bot] commented on code in PR #40338:
URL: https://github.com/apache/superset/pull/40338#discussion_r3285092995
##########
superset/common/query_context_processor.py:
##########
@@ -276,7 +290,10 @@ def get_query_result(self, query_object: QueryObject) ->
QueryResult:
# todo(hugh): add logic to manage all sip68 models here
result = query_context.datasource.exc_query(query_object.to_dict())
else:
- result = query_context.datasource.query(query_object.to_dict())
+ result = query_context.datasource.query(
+ query_object.to_dict(),
+ mutation_context=self._get_sql_mutation_context(),
+ )
Review Comment:
**Suggestion:** The new mutation context is only wired into the non-`Query`
datasource path, so charts backed by `query`/`saved_query` datasources still
bypass this context entirely. That means dashboard and slice identifiers are
not exposed for those chart queries, which makes the feature incomplete and
breaks job-to-dashboard mapping for that datasource type. [incomplete
implementation]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Saved-query charts lack dashboard_id in SQL mutator.
- ⚠️ Saved-query charts lack slice_id in SQL mutator.
- ⚠️ Job-to-dashboard mapping incomplete for query datasources.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Configure a SQL query mutator in `superset/config.py` (e.g.
`SQL_QUERY_MUTATOR =
my_mutator`) that inspects incoming kwargs and logs `dashboard_id` and
`slice_id` when
present.
2. Create two charts: (a) a regular chart based on a physical table
datasource (SqlaTable)
and (b) a chart based on a `query`/saved_query datasource (backed by the
`Query` model
referenced in `superset/common/query_context_processor.py:702` via
`isinstance(self._qc_datasource, Query)`), and add both to the same
dashboard.
3. Load the dashboard so that Flask hits the chart data endpoint, which
builds a
`QueryContext` and invokes `QueryContextProcessor.get_query_result()` in
`superset/common/query_context_processor.py:281`.
4. Observe that for the table-based chart, `get_query_result` takes the
`else` branch and
calls `query_context.datasource.query(query_object.to_dict(),
mutation_context=self._get_sql_mutation_context())` at
`superset/common/query_context_processor.py:293–296`, so the mutator receives
`dashboard_id`/`slice_id`; but for the saved-query chart,
`query_context.datasource` is a
`Query` instance so `get_query_result` uses
`query_context.datasource.exc_query(query_object.to_dict())` at
`superset/common/query_context_processor.py:291` and the separate
`processing_time_offsets` path uses
`self._qc_datasource.exc_query(query_object_clone_dct)` at
`superset/common/query_context_processor.py:702`—neither call path passes
`mutation_context`, so the configured `SQL_QUERY_MUTATOR` never sees
`dashboard_id`/`slice_id` for query-backed charts.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c560f23800df40d587dabc4d21864745&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=c560f23800df40d587dabc4d21864745&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_context_processor.py
**Line:** 293:296
**Comment:**
*Incomplete Implementation: The new mutation context is only wired into
the non-`Query` datasource path, so charts backed by `query`/`saved_query`
datasources still bypass this context entirely. That means dashboard and slice
identifiers are not exposed for those chart queries, which makes the feature
incomplete and breaks job-to-dashboard mapping for that datasource type.
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%2F40338&comment_hash=99f7daa377259d466aec787ad3af7f87871714a6974e7040f7098cf6dc683305&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40338&comment_hash=99f7daa377259d466aec787ad3af7f87871714a6974e7040f7098cf6dc683305&reaction=dislike'>👎</a>
##########
superset/models/core.py:
##########
@@ -666,6 +671,7 @@ def mutate_sql_based_on_config(self, sql_: str, is_split:
bool = False) -> str:
sql_,
security_manager=security_manager,
database=self,
+ **kwargs,
)
Review Comment:
**Suggestion:** Forwarding arbitrary `**kwargs` directly into
`SQL_QUERY_MUTATOR` introduces a backward-incompatible runtime break for
existing mutator functions that only accept `sql`, `security_manager`, and
`database` (as documented in existing examples). Once chart queries start
passing `dashboard_id`/`slice_id`/`form_data`, those deployments will raise
`TypeError: got an unexpected keyword argument ...`. Keep compatibility by
filtering supported kwargs or gracefully falling back when the mutator doesn't
accept extra parameters. [api mismatch]
<details>
<summary><b>Severity Level:</b> Critical 🚨</summary>
```mdx
- ❌ Chart queries fail when SQL_QUERY_MUTATOR lacks **kwargs.
- ❌ Dashboards break on instances with existing mutators.
- ⚠️ Deployments risk runtime errors after upgrading.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. In `superset/config.py`, configure `SQL_QUERY_MUTATOR` with the
previously documented
signature that does not accept arbitrary kwargs, for example:
`def my_mutator(sql, security_manager=None, database=None): return sql`;
then set
`SQL_QUERY_MUTATOR = my_mutator`.
2. Create a regular chart based on a physical table datasource (SqlaTable),
add it to a
dashboard, and open the dashboard so that Flask invokes the chart data API,
which builds a
`QueryContext` and calls `QueryContextProcessor.get_query_result()` in
`superset/common/query_context_processor.py:281`.
3. In `get_query_result`, for non-`Query` datasources the code calls
`query_context.datasource.query(query_object.to_dict(),
mutation_context=self._get_sql_mutation_context())` at
`superset/common/query_context_processor.py:293–296`, where
`_get_sql_mutation_context()`
includes `dashboard_id`, `slice_id`, and `form_data` (lines 267–279) in the
`mutation_context` dict.
4. Inside the SQLAlchemy datasource implementation (`SqlaTable.query` in
`superset/connectors/sqla/models.py`), the `mutation_context` dict is
forwarded down to
the database layer, which calls `Database.mutate_sql_based_on_config(...)` in
`superset/models/core.py:652–657`; the new implementation invokes
`sql_mutator(sql_,
security_manager=security_manager, database=self, **kwargs)` at
`superset/models/core.py:671–675`, causing Python to raise `TypeError:
my_mutator() got an
unexpected keyword argument 'dashboard_id'` (or similar) because
`my_mutator` does not
accept these extra kwargs, resulting in a 500 error for the chart query.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f7d38c2760894922ad187858ed225b93&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=f7d38c2760894922ad187858ed225b93&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/models/core.py
**Line:** 671:675
**Comment:**
*Api Mismatch: Forwarding arbitrary `**kwargs` directly into
`SQL_QUERY_MUTATOR` introduces a backward-incompatible runtime break for
existing mutator functions that only accept `sql`, `security_manager`, and
`database` (as documented in existing examples). Once chart queries start
passing `dashboard_id`/`slice_id`/`form_data`, those deployments will raise
`TypeError: got an unexpected keyword argument ...`. Keep compatibility by
filtering supported kwargs or gracefully falling back when the mutator doesn't
accept extra parameters.
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%2F40338&comment_hash=a171803f820f1567579330a082376d28b9cd25b6b1eba71fe0a950c7f104c31c&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40338&comment_hash=a171803f820f1567579330a082376d28b9cd25b6b1eba71fe0a950c7f104c31c&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]