This is an automated email from the ASF dual-hosted git repository.
kgabryje pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new b92909d621 feat: Enable passing a permalink to
cache_dashboard_screenshot endpoint (#32900)
b92909d621 is described below
commit b92909d621edc9a2298f4f5ea54bb07829c9ec7b
Author: Kamil Gabryjelski <[email protected]>
AuthorDate: Mon Mar 31 10:40:36 2025 +0200
feat: Enable passing a permalink to cache_dashboard_screenshot endpoint
(#32900)
---
superset/dashboards/api.py | 17 ++++++++++-------
superset/dashboards/schemas.py | 1 +
superset/utils/screenshots.py | 5 ++---
tests/integration_tests/dashboards/api_tests.py | 12 ++++++++++++
4 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py
index c7becfe8a1..b578ee081d 100644
--- a/superset/dashboards/api.py
+++ b/superset/dashboards/api.py
@@ -1087,16 +1087,19 @@ class DashboardRestApi(BaseSupersetModelRestApi):
"urlParams": payload.get("urlParams", []),
}
- permalink_key = CreateDashboardPermalinkCommand(
- dashboard_id=str(dashboard.id),
- state=dashboard_state,
- ).run()
+ # if the permalink key is provided, dashboard_state will be ignored
+ # else, create a permalink key from the dashboard_state
+ permalink_key = (
+ payload.get("permalinkKey", None)
+ or CreateDashboardPermalinkCommand(
+ dashboard_id=str(dashboard.id),
+ state=dashboard_state,
+ ).run()
+ )
dashboard_url = get_url_path("Superset.dashboard_permalink",
key=permalink_key)
screenshot_obj = DashboardScreenshot(dashboard_url, dashboard.digest)
- cache_key = screenshot_obj.get_cache_key(
- window_size, thumb_size, dashboard_state
- )
+ cache_key = screenshot_obj.get_cache_key(window_size, thumb_size,
permalink_key)
image_url = get_url_path(
"DashboardRestApi.screenshot", pk=dashboard.id, digest=cache_key
)
diff --git a/superset/dashboards/schemas.py b/superset/dashboards/schemas.py
index ded8324669..88ad279855 100644
--- a/superset/dashboards/schemas.py
+++ b/superset/dashboards/schemas.py
@@ -521,3 +521,4 @@ class CacheScreenshotSchema(Schema):
urlParams = fields.List( # noqa: N815
fields.List(fields.Str(), validate=lambda x: len(x) == 2),
required=False
)
+ permalinkKey = fields.Str(required=False) # noqa: N815
diff --git a/superset/utils/screenshots.py b/superset/utils/screenshots.py
index 74a1f0746f..cf28dcf916 100644
--- a/superset/utils/screenshots.py
+++ b/superset/utils/screenshots.py
@@ -26,7 +26,6 @@ from typing import cast, TYPE_CHECKING, TypedDict
from flask import current_app
from superset import app, feature_flag_manager, thumbnail_cache
-from superset.dashboards.permalink.types import DashboardPermalinkState
from superset.extensions import event_logger
from superset.utils.hashing import md5_sha_from_dict
from superset.utils.urls import modify_url_query
@@ -349,7 +348,7 @@ class DashboardScreenshot(BaseScreenshot):
self,
window_size: bool | WindowSize | None = None,
thumb_size: bool | WindowSize | None = None,
- dashboard_state: DashboardPermalinkState | None = None,
+ permalink_key: str | None = None,
) -> str:
window_size = window_size or self.window_size
thumb_size = thumb_size or self.thumb_size
@@ -359,6 +358,6 @@ class DashboardScreenshot(BaseScreenshot):
"type": "thumb",
"window_size": window_size,
"thumb_size": thumb_size,
- "dashboard_state": dashboard_state,
+ "permalink_key": permalink_key,
}
return md5_sha_from_dict(args)
diff --git a/tests/integration_tests/dashboards/api_tests.py
b/tests/integration_tests/dashboards/api_tests.py
index 56062dc852..291096deb6 100644
--- a/tests/integration_tests/dashboards/api_tests.py
+++ b/tests/integration_tests/dashboards/api_tests.py
@@ -3038,6 +3038,18 @@ class TestDashboardApi(ApiOwnersTestCaseMixin,
InsertChartMixin, SupersetTestCas
response = self._cache_screenshot(dashboard.id)
assert response.status_code == 202
+ @with_feature_flags(THUMBNAILS=True,
ENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS=True)
+ @pytest.mark.usefixtures("create_dashboard_with_tag")
+ def test_cache_dashboard_screenshot_success_permalink_payload(self):
+ self.login(ADMIN_USERNAME)
+ dashboard = (
+ db.session.query(Dashboard)
+ .filter(Dashboard.dashboard_title == "dash with tag")
+ .first()
+ )
+ response = self._cache_screenshot(dashboard.id, {"permalinkKey":
"1234"})
+ assert response.status_code == 202
+
@with_feature_flags(THUMBNAILS=True,
ENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS=True)
@pytest.mark.usefixtures("create_dashboard_with_tag")
def test_cache_dashboard_screenshot_dashboard_validation(self):