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 2026/07/22 00:05:07 UTC

(superset) branch master updated: fix(cache): QueryCacheManager.get() should fail open on cache backend errors (#42252)

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

aminghadersohi 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 cae61b51e12 fix(cache): QueryCacheManager.get() should fail open on cache backend errors (#42252)
cae61b51e12 is described below

commit cae61b51e123317d3e47bd7ee6c98887102a51dd
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Tue Jul 21 20:05:00 2026 -0400

    fix(cache): QueryCacheManager.get() should fail open on cache backend errors (#42252)
---
 superset/common/utils/query_cache_manager.py       | 11 ++++-
 .../unit_tests/common/test_query_cache_manager.py  | 57 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/superset/common/utils/query_cache_manager.py b/superset/common/utils/query_cache_manager.py
index a7a97e2b874..6d7b64041a5 100644
--- a/superset/common/utils/query_cache_manager.py
+++ b/superset/common/utils/query_cache_manager.py
@@ -177,7 +177,16 @@ class QueryCacheManager:
         if not key or not _cache[region] or force_query:
             return query_cache
 
-        if cache_value := _cache[region].get(key):
+        try:
+            cache_value = _cache[region].get(key)
+        except Exception as ex:  # pylint: disable=broad-except
+            # A cache backend outage (e.g. Redis connection/timeout errors)
+            # should not surface as an error to the caller: treat it the
+            # same as a cache miss and fall through to querying live data.
+            logger.warning("Error reading cache: %s", error_msg_from_exception(ex))
+            cache_value = None
+
+        if cache_value:
             logger.debug("Cache key: %s", key)
             # Log cache hit for debugging
             logger.debug("CACHE GET - Key: %s, Region: %s", key, region)
diff --git a/tests/unit_tests/common/test_query_cache_manager.py b/tests/unit_tests/common/test_query_cache_manager.py
new file mode 100644
index 00000000000..183250fa2ad
--- /dev/null
+++ b/tests/unit_tests/common/test_query_cache_manager.py
@@ -0,0 +1,57 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from unittest.mock import MagicMock, patch
+
+from superset.common.utils.query_cache_manager import QueryCacheManager
+from superset.constants import CacheRegion
+
+
+class TestQueryCacheManagerGet:
+    def test_get_cache_miss(self):
+        """A regular cache miss returns an empty, non-loaded QueryCacheManager."""
+        mock_cache = MagicMock()
+        mock_cache.get.return_value = None
+
+        with patch(
+            "superset.common.utils.query_cache_manager._cache",
+            {CacheRegion.DEFAULT: mock_cache},
+        ):
+            result = QueryCacheManager.get(key="some-key")
+
+        assert result.is_loaded is False
+        assert result.cache_value is None
+
+    def test_get_cache_backend_error_fails_open(self):
+        """
+        If the cache backend raises on read (e.g. a Redis connection or
+        timeout error), QueryCacheManager.get() should not propagate the
+        exception. It should behave exactly like a cache miss so callers
+        fall back to querying live data.
+        """
+        mock_cache = MagicMock()
+        mock_cache.get.side_effect = ConnectionError("connection refused")
+
+        with patch(
+            "superset.common.utils.query_cache_manager._cache",
+            {CacheRegion.DEFAULT: mock_cache},
+        ):
+            result = QueryCacheManager.get(key="some-key")
+
+        miss_result = QueryCacheManager()
+        assert result.is_loaded == miss_result.is_loaded
+        assert result.cache_value == miss_result.cache_value
+        assert result.status == miss_result.status