You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2022/01/10 17:25:32 UTC

[superset] branch master updated: fix: Returns 404 instead of 500 for unknown dashboard filter state keys (#17878)

This is an automated email from the ASF dual-hosted git repository.

michaelsmolina 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 3a9bd12  fix: Returns 404 instead of 500 for unknown dashboard filter state keys (#17878)
3a9bd12 is described below

commit 3a9bd12e3d294450e703ed87937e8e2c6308216e
Author: Michael S. Molina <70...@users.noreply.github.com>
AuthorDate: Mon Jan 10 14:24:22 2022 -0300

    fix: Returns 404 instead of 500 for unknown dashboard filter state keys (#17878)
    
    * fix: Returns 404 instead of 500 for unknown dashboard filter state keys
    
    * Reduces hierarchies of if-expression
    
    * Removes unnecessary check
    
    Co-authored-by: Ville Brofeldt <33...@users.noreply.github.com>
    
    * Removes unused variable
    
    * Fixes type error
    
    * Removes unused import
    
    Co-authored-by: Ville Brofeldt <33...@users.noreply.github.com>
---
 superset/dashboards/filter_state/commands/get.py          | 15 +++++----------
 .../dashboards/filter_state/api_tests.py                  |  4 ++--
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/superset/dashboards/filter_state/commands/get.py b/superset/dashboards/filter_state/commands/get.py
index 3087389..bb3e95a 100644
--- a/superset/dashboards/filter_state/commands/get.py
+++ b/superset/dashboards/filter_state/commands/get.py
@@ -17,7 +17,6 @@
 from typing import Optional
 
 from superset.dashboards.dao import DashboardDAO
-from superset.dashboards.filter_state.commands.entry import Entry
 from superset.extensions import cache_manager
 from superset.key_value.commands.get import GetKeyValueCommand
 from superset.key_value.utils import cache_key
@@ -25,12 +24,8 @@ from superset.key_value.utils import cache_key
 
 class GetFilterStateCommand(GetKeyValueCommand):
     def get(self, resource_id: int, key: str, refresh_timeout: bool) -> Optional[str]:
-        dashboard = DashboardDAO.get_by_id_or_slug(str(resource_id))
-        if dashboard:
-            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"]
-        return None
+        DashboardDAO.get_by_id_or_slug(str(resource_id))
+        entry = cache_manager.filter_state_cache.get(cache_key(resource_id, key)) or {}
+        if entry and refresh_timeout:
+            cache_manager.filter_state_cache.set(key, entry)
+        return entry.get("value")
diff --git a/tests/integration_tests/dashboards/filter_state/api_tests.py b/tests/integration_tests/dashboards/filter_state/api_tests.py
index dce0620..ae667ec 100644
--- a/tests/integration_tests/dashboards/filter_state/api_tests.py
+++ b/tests/integration_tests/dashboards/filter_state/api_tests.py
@@ -145,9 +145,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