EnxDev commented on code in PR #44849:
URL: https://github.com/apache/superset/pull/44849#discussion_r4212391837
##########
superset/models/slice.py:
##########
@@ -404,6 +404,28 @@ def form_data(self) -> dict[str, Any]:
update_time_range(form_data)
return form_data
+ def get_query_context_datasource(self) -> Datasource | None:
+ """Resolve the saved query source without constructing queries or
metadata."""
+ from superset.daos.datasource import DatasourceDAO
+ from superset.daos.exceptions import DatasourceNotFound
+
+ if self.query_context:
+ try:
+ datasource: utils.DatasourceDict =
json.loads(self.query_context)[
+ "datasource"
+ ]
+ except json.JSONDecodeError:
+ # Match get_query_context's missing-context fallback.
+ return self.resolved_datasource
+ try:
+ return DatasourceDAO.get_datasource(
+ datasource_type=utils.DatasourceType(datasource["type"]),
+ database_id_or_uuid=datasource["id"],
+ )
+ except DatasourceNotFound:
+ return self.resolved_datasource
Review Comment:
Only `DatasourceNotFound` falls back here. A saved context of `"null"`, one
with no `datasource` key, or a type the DAO doesn't serve (`"dataset"`, a
leftover `"druid"`) escapes as TypeError, KeyError,
DatasourceTypeNotSupportedError or ValueError. I checked all four against this
head.
`_annotation_cache_context` calls this to build the key for any chart with a
chart-backed annotation, with the flag on or off and on cache hits too, so the
host chart becomes a 500 where `chart.datasource` never raised. Could both
`except`s fall back the way `resolved_datasource` does, with those shapes added
to `test_deleted_annotation_source_uses_relationship_fallback`?
--
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]