From e6bfc2c63593c73d0f308a2edc5296fd722e32fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B6xtermann?= Date: Sat, 12 Apr 2025 09:29:48 +0200 Subject: [PATCH] fix(thumbnails): handle remaining thumbnail states - if thumbnail is COMPUTING then 202 without creating a new task - if thumbnail is ERROR (or missing for some other reason) then 404 --- superset/dashboards/api.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py index b578ee081d01..93b06941f15a 100644 --- a/superset/dashboards/api.py +++ b/superset/dashboards/api.py @@ -116,6 +116,7 @@ DashboardScreenshot, DEFAULT_DASHBOARD_WINDOW_SIZE, ScreenshotCachePayload, + StatusValues, ) from superset.utils.urls import get_url_path from superset.views.base_api import ( @@ -1307,6 +1308,11 @@ def thumbnail(self, pk: int, digest: str, **kwargs: Any) -> WerkzeugResponse: dashboard_id=dashboard.id, force=False, ) + + if ( + cache_payload.should_trigger_task() + or cache_payload.status == StatusValues.COMPUTING + ): return self.response( 202, cache_key=cache_key, @@ -1316,12 +1322,15 @@ def thumbnail(self, pk: int, digest: str, **kwargs: Any) -> WerkzeugResponse: task_status=cache_payload.get_status(), ) - self.incr_stats("from_cache", self.thumbnail.__name__) - return Response( - FileWrapper(cache_payload.get_image()), - mimetype="image/png", - direct_passthrough=True, - ) + if image := cache_payload.get_image(): + self.incr_stats("from_cache", self.thumbnail.__name__) + return Response( + FileWrapper(image), + mimetype="image/png", + direct_passthrough=True, + ) + else: + return self.response_404() @expose("/favorite_status/", methods=("GET",)) @protect()