bito-code-review[bot] commented on code in PR #39898:
URL: https://github.com/apache/superset/pull/39898#discussion_r3192215586
##########
superset/mcp_service/dataset/schemas.py:
##########
@@ -93,6 +93,29 @@ class TableColumnInfo(BaseModel):
filterable: bool | None = Field(None, description="Is filterable")
description: str | None = Field(None, description="Column description")
+ @model_serializer(mode="wrap")
+ def _filter_column_fields_by_context(
+ self, serializer: Any, info: Any
+ ) -> Dict[str, Any]:
+ """Filter column fields based on serialization context.
+
+ If context contains 'column_fields', only include those fields.
+ Otherwise, include all fields. This trims wide datasets so a
+ 50-column dataset doesn't ship 50 long descriptions when the
+ caller only needs column_name + type.
+ """
+ data = serializer(self)
+
+ if info.context and isinstance(info.context, dict):
+ column_fields = info.context.get("column_fields")
+ if column_fields:
+ requested = set(column_fields)
+ # Always preserve column_name as the only required field
+ requested.add("column_name")
+ return {k: v for k, v in data.items() if k in requested}
+
+ return data
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incorrect Filtering Logic</b></div>
<div id="fix">
The serializer skips filtering when `column_fields` is an empty list,
returning all fields instead of just `column_name`. This can lead to
unexpectedly large responses if users pass `[]` intending minimal output.
Update the logic to always filter when the key is present, defaulting to only
`column_name` for empty lists.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
if info.context and isinstance(info.context, dict):
column_fields = info.context.get("column_fields")
if "column_fields" in info.context:
requested = set(column_fields or [])
# Always preserve column_name as the only required field
requested.add("column_name")
return {k: v for k, v in data.items() if k in requested}
return data
````
</div>
</details>
</div>
<small><i>Code Review Run #f4f326</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]