YuriyKrasilnikov commented on code in PR #37790:
URL: https://github.com/apache/superset/pull/37790#discussion_r2779269666
##########
superset/dashboards/schemas.py:
##########
@@ -445,6 +574,50 @@ class DashboardPutSchema(BaseDashboardSchema):
fields.Integer(metadata={"description": tags_description},
allow_none=True)
)
uuid = fields.UUID(allow_none=True)
+ translations = fields.Dict(
+ metadata={"description": "Translations dict for content localization"},
+ allow_none=True,
+ )
+
+ @validates_schema
+ def validate_translations_data(
+ self, data: dict[str, Any], **kwargs: Any
+ ) -> None:
+ """
+ Validate translations field: feature flag and structure.
+
+ Checks:
+ 1. Feature flag ENABLE_CONTENT_LOCALIZATION must be enabled
+ 2. Structure must be valid: {field: {locale: value}}
+
+ Raises:
+ ValidationError: If feature disabled or structure invalid.
+ """
+ if "translations" not in data:
+ return
+
+ if not is_feature_enabled("ENABLE_CONTENT_LOCALIZATION"):
+ raise ValidationError(
+ "Content localization is not enabled. "
+ "Set ENABLE_CONTENT_LOCALIZATION=True to use translations.",
+ field_name="translations",
+ )
+
+ validate_translations(data["translations"])
Review Comment:
False positive. `validate_translations()` explicitly handles `None` as the
first guard clause:
```python
# superset/localization/validation.py:128-129
if translations is None:
return
```
The function signature also declares `None` as a valid input: `translations:
dict[str, dict[str, str]] | None`.
The call chain is safe:
1. `allow_none=True` on the Marshmallow field → `data["translations"]` can
be `None`
2. `validate_translations(None)` → early return, no TypeError
--
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]