bito-code-review[bot] commented on code in PR #36035:
URL: https://github.com/apache/superset/pull/36035#discussion_r2501022167
##########
superset/mcp_service/chart/tool/list_charts.py:
##########
@@ -95,8 +95,23 @@ async def list_charts(request: ListChartsRequest, ctx:
Context) -> ChartList:
from superset.daos.chart import ChartDAO
def _serialize_chart(obj: "Slice | None", cols: Any) -> ChartInfo | None:
- """Serialize chart object with proper type casting."""
- return serialize_chart_object(cast(ChartLike | None, obj))
+ """Serialize chart object with proper type casting and column
selection."""
+ full_chart = serialize_chart_object(cast(ChartLike | None, obj))
+ if not full_chart:
+ return None
+
+ # If columns were specified, exclude fields not in the selection
+ # Always include 'id' as it's the primary identifier
+ if cols and isinstance(cols, list):
+ all_fields = set(ChartInfo.model_fields.keys())
+ requested_fields = set(cols) | {"id"} # Always include id
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing required fields in column selection</b></div>
<div id="fix">
The column selection logic in `_serialize_chart` only ensures 'id' is
included but misses other required fields like 'slice_name'. This causes a
ValidationError when creating `ChartInfo` if `select_columns` excludes required
fields, breaking chart listing functionality. The `ChartInfo` model requires
both 'id' and 'slice_name' fields, so the fix updates `requested_fields` to
always include both.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
requested_fields = set(cols) | {"id", "slice_name"} # Always
include id and slice_name
````
</div>
</details>
</div>
<small><i>Code Review Run <a
href=https://github.com/apache/superset/pull/36035#issuecomment-3499545460>#88d182</a></i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]