rusackas commented on code in PR #43177:
URL: https://github.com/apache/superset/pull/43177#discussion_r3845515083
##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx:
##########
@@ -196,6 +196,42 @@ interface DatasourceObject {
folders?: DatasourceFolder[];
}
+/**
+ * Lift the certification and warning fields a metric keeps inside its `extra`
+ * JSON blob onto the metric itself, which is the shape the editor's fields
bind
+ * to.
+ *
+ * Two entry points feed the editor two different metric shapes: the dataset
+ * list hands over the API payload, where `extra` is still a JSON string, while
+ * Explore hands over its bootstrap payload, where `SqlMetric.data` has already
+ * flattened `extra` into `warning_markdown` and dropped the raw string. The
+ * parsed blob is therefore only authoritative when `extra` is actually
present;
+ * otherwise the already-flattened value stands, instead of being reset to an
+ * empty field.
+ */
+export function hydrateMetricExtra(metric: Metric): Metric {
+ const {
+ certified_by: certifiedByMetric,
+ certification_details: certificationDetails,
+ } = metric;
+ const parsedExtra = metric.extra ? JSON.parse(metric.extra) || {} :
undefined;
+ const {
+ certification: {
+ details = undefined,
+ certified_by: certifiedBy = undefined,
+ } = {},
+ } = parsedExtra || {};
+ const warningMarkdown = parsedExtra
+ ? parsedExtra.warning_markdown
+ : metric.warning_markdown;
Review Comment:
Good catch, and correcting the record here since the earlier bot reply
claiming this was already handled was wrong — there was no try/catch anywhere.
Wrapped the `JSON.parse` in `hydrateMetricExtra` in try/catch, falling back to
the already-flattened value on malformed `extra` instead of throwing during
editor init, matching the backend's own tolerance for bad `extra` JSON in
`CertificationMixin.get_extra_dict()`. Added a regression test for the
malformed-extra case.
--
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]