rusackas commented on code in PR #44043:
URL: https://github.com/apache/superset/pull/44043#discussion_r3975163098
##########
superset/commands/dashboard/filter_state/get.py:
##########
@@ -40,3 +42,48 @@ def get(self, cmd_params: CommandParameters) ->
Optional[str]:
if entry and self._refresh_timeout:
cache_manager.filter_state_cache.set(key, entry)
return entry.get("value")
+
+ @staticmethod
+ def get_filter_names(resource_id: int, value: Optional[str]) -> dict[str,
str]:
+ """
+ Cross-reference the filter ids present in a cached filter_state
+ ``value`` (a ``DataMaskStateWithId``, i.e. a map keyed by filter id)
+ against the dashboard's ``native_filter_configuration`` to build a
+ map of filter id -> human-readable filter label.
+
+ The cached blob itself has no notion of a filter's label: that only
+ lives in the dashboard's filter configuration metadata (#36053).
+ """
+ if not value:
+ return {}
+ try:
+ parsed_value = json.loads(value)
+ except (json.JSONDecodeError, TypeError):
+ return {}
+ if not isinstance(parsed_value, dict):
+ return {}
+
+ dashboard = DashboardDAO.get_by_id_or_slug(str(resource_id))
+ try:
+ metadata = json.loads(dashboard.json_metadata or "{}")
+ except (json.JSONDecodeError, TypeError):
+ return {}
+ if not isinstance(metadata, dict):
+ return {}
+
+ native_filters: list[dict[str, Any]] = metadata.get(
+ "native_filter_configuration", []
+ )
+ id_to_name = {
+ native_filter["id"]: native_filter["name"]
+ for native_filter in native_filters
Review Comment:
Good catch, this one's real. `.get("native_filter_configuration", [])` only
falls back when the key is missing, but a dashboard can have it explicitly
persisted as `null`. Normalized with `or []` and added a regression test for
that case in af3da2f.
--
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]