aminghadersohi commented on code in PR #40957:
URL: https://github.com/apache/superset/pull/40957#discussion_r3493687650
##########
superset/mcp_service/dashboard/schemas.py:
##########
@@ -871,6 +902,32 @@ def sanitize_dashboard_title(cls, v: str | None) -> str |
None:
v, "Dashboard title", max_length=500, allow_empty=True
)
+ @field_validator("slug")
+ @classmethod
+ def normalize_slug(cls, v: str | None) -> str | None:
+ """Normalize the slug to match the REST DashboardPutSchema contract.
+
+ Mirrors ``BaseDashboardSchema.post_load``: strip, replace spaces with
+ hyphens, and drop characters outside ``[\\w-]`` so the tool cannot
+ persist slugs the REST update path would have cleaned.
+
+ Whitespace-only inputs normalize to ``""`` (clears the slug), matching
+ REST schema behavior. Raises ``ValueError`` when a non-whitespace input
+ normalizes to empty (e.g. ``"!!!"``), preventing accidental slug
clearing.
+ """
+ if not v:
+ return v
+ stripped = v.strip()
Review Comment:
Declining as a nit — `stripped` is a trivially inferred `str`. Covered by
the existing custom instruction saved on the `_TYPED_METADATA_FIELDS` thread.
##########
superset/mcp_service/dashboard/schemas.py:
##########
@@ -871,6 +902,32 @@ def sanitize_dashboard_title(cls, v: str | None) -> str |
None:
v, "Dashboard title", max_length=500, allow_empty=True
)
+ @field_validator("slug")
+ @classmethod
+ def normalize_slug(cls, v: str | None) -> str | None:
+ """Normalize the slug to match the REST DashboardPutSchema contract.
+
+ Mirrors ``BaseDashboardSchema.post_load``: strip, replace spaces with
+ hyphens, and drop characters outside ``[\\w-]`` so the tool cannot
+ persist slugs the REST update path would have cleaned.
+
+ Whitespace-only inputs normalize to ``""`` (clears the slug), matching
+ REST schema behavior. Raises ``ValueError`` when a non-whitespace input
+ normalizes to empty (e.g. ``"!!!"``), preventing accidental slug
clearing.
+ """
+ if not v:
+ return v
+ stripped = v.strip()
+ if not stripped:
+ return "" # whitespace-only → same as empty string (clears slug)
+ normalized = re.sub(r"[^\w\-]+", "", stripped.replace(" ", "-"))
Review Comment:
Declining as a nit — `normalized` is a trivially inferred `str`. Covered by
the existing custom instruction.
--
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]