From 030d322d247d1a4136485bf043f1e3519fe39c78 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Mon, 27 Dec 2021 13:43:04 -0300 Subject: [PATCH] fix: Returns 404 instead of 500 for unknown dashboard filter state keys --- superset/dashboards/filter_state/commands/get.py | 7 ++++--- .../integration_tests/dashboards/filter_state/api_tests.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/superset/dashboards/filter_state/commands/get.py b/superset/dashboards/filter_state/commands/get.py index 3087389cc5a2e..6f571cf91bf9a 100644 --- a/superset/dashboards/filter_state/commands/get.py +++ b/superset/dashboards/filter_state/commands/get.py @@ -30,7 +30,8 @@ def get(self, resource_id: int, key: str, refresh_timeout: bool) -> Optional[str entry: Entry = cache_manager.filter_state_cache.get( cache_key(resource_id, key) ) - if refresh_timeout: - cache_manager.filter_state_cache.set(key, entry) - return entry["value"] + if entry: + if refresh_timeout: + cache_manager.filter_state_cache.set(key, entry) + return entry["value"] return None diff --git a/tests/integration_tests/dashboards/filter_state/api_tests.py b/tests/integration_tests/dashboards/filter_state/api_tests.py index bd0e2e7d97753..00e88624909f8 100644 --- a/tests/integration_tests/dashboards/filter_state/api_tests.py +++ b/tests/integration_tests/dashboards/filter_state/api_tests.py @@ -146,9 +146,9 @@ def test_put_not_owner(client, dashboard_id: int): assert resp.status_code == 403 -def test_get_key_not_found(client): +def test_get_key_not_found(client, dashboard_id: int): login(client, "admin") - resp = client.get("unknown-key") + resp = client.get(f"api/v1/dashboard/{dashboard_id}/filter_state/unknown-key/") assert resp.status_code == 404