aminghadersohi commented on code in PR #39898:
URL: https://github.com/apache/superset/pull/39898#discussion_r3192222129


##########
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:
   Already addressed via a different layer in b888574b16 — the 
`_parse_column_fields` field_validator on `GetDatasetInfoRequest` coerces an 
empty list (and None) back to `DEFAULT_GET_DATASET_INFO_COLUMN_FIELDS`, so the 
serializer never sees an empty `column_fields` at runtime. Same outcome you 
wanted (no caller silently re-enables verbose per-column fields), but resolved 
before the model is constructed rather than inside the serializer. Regression 
test in `test_get_dataset_info_empty_lists_fall_back_to_defaults` and 
`test_get_dataset_info_request_empty_lists_use_defaults`.



-- 
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]

Reply via email to