You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "michael-s-molina (via GitHub)" <gi...@apache.org> on 2023/07/19 16:19:55 UTC

[GitHub] [superset] michael-s-molina commented on a diff in pull request #24671: fix(cache): Add cache warmup for non-legacy charts

michael-s-molina commented on code in PR #24671:
URL: https://github.com/apache/superset/pull/24671#discussion_r1268312671


##########
superset/charts/commands/warm_up_cache.py:
##########
@@ -43,31 +48,51 @@ def __init__(
     def run(self) -> dict[str, Any]:
         self.validate()
         chart: Slice = self._chart_or_id  # type: ignore
+
         try:
             form_data = get_form_data(chart.id, use_slice_data=True)[0]
-            if self._dashboard_id:
-                form_data["extra_filters"] = (
-                    json.loads(self._extra_filters)
-                    if self._extra_filters
-                    else get_dashboard_extra_filters(chart.id, self._dashboard_id)
-                )
-
-            if not chart.datasource:
-                raise Exception("Chart's datasource does not exist")
-
-            obj = get_viz(
-                datasource_type=chart.datasource.type,
-                datasource_id=chart.datasource.id,
-                form_data=form_data,
-                force=True,
-            )
-
-            # pylint: disable=assigning-non-slot
-            g.form_data = form_data
-            payload = obj.get_payload()
-            delattr(g, "form_data")
-            error = payload["errors"] or None
-            status = payload["status"]
+
+            if form_data.get("viz_type") in viz_types:
+                # Legacy visualizations.
+                if not chart.datasource:
+                    raise ChartInvalidError("Chart's datasource does not exist")
+
+                if self._dashboard_id:
+                    form_data["extra_filters"] = (
+                        json.loads(self._extra_filters)
+                        if self._extra_filters
+                        else get_dashboard_extra_filters(chart.id, self._dashboard_id)
+                    )
+
+                g.form_data = form_data  # pylint: disable=assigning-non-slot
+                payload = get_viz(
+                    datasource_type=chart.datasource.type,
+                    datasource_id=chart.datasource.id,
+                    form_data=form_data,
+                    force=True,
+                ).get_payload()
+                delattr(g, "form_data")
+                error = payload["errors"] or None
+                status = payload["status"]
+            else:
+                # Non-legacy visualizations.
+                query_context = chart.get_query_context()
+
+                if not query_context:
+                    raise ChartInvalidError("Chart's query context does not exist")
+
+                query_context.force = True
+                command = ChartDataCommand(query_context)
+                command.validate()
+                payload = command.run()
+
+                # Report the first error.
+                for query in payload["queries"]:
+                    error = query["error"]
+                    status = query["status"]
+
+                    if error is not None:
+                        break
         except Exception as ex:  # pylint: disable=broad-except
             error = error_msg_from_exception(ex)
             status = None

Review Comment:
   Do we have a status for errors?



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org