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/10/20 16:40:46 UTC
(superset) branch master updated: fix(cache): honor disabled datasource suggestion caches (#45288)
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 38353434467 fix(cache): honor disabled datasource suggestion caches (#45288)
38353434467 is described below
commit 38353434467b33aec4fc6e4193ee88a21a0e7c92
Author: Mike Bridge <mi...@preset.io>
AuthorDate: Tue Oct 20 10:40:39 2026 -0600
fix(cache): honor disabled datasource suggestion caches (#45288)
Co-authored-by: Mike Bridge <mi...@ext.preset.io>
---
docs/admin_docs/configuration/cache.mdx | 16 ++
superset/datasource/api.py | 32 ++--
.../semantic_layers/execution_context_test.py | 3 +-
.../semantic_layers/values_endpoint_test.py | 184 +++++++++++++++++++++
4 files changed, 224 insertions(+), 11 deletions(-)
diff --git a/docs/admin_docs/configuration/cache.mdx b/docs/admin_docs/configuration/cache.mdx
index 4ba72ee0609..e30c454a9ff 100644
--- a/docs/admin_docs/configuration/cache.mdx
+++ b/docs/admin_docs/configuration/cache.mdx
@@ -112,6 +112,22 @@ value defined in `DATA_CACHE_CONFIG`.
Note, that by setting the cache timeout to `-1`, caching for charting data can be disabled, either
per chart, dataset or database, or by default if set in `DATA_CACHE_CONFIG`.
+The datasource column-values and compatibility endpoints skip cache reads and writes when
+their effective timeout is `-1`. They use the datasource timeout (for SQL datasets, falling
+back to the database timeout), then the **top-level** `CACHE_DEFAULT_TIMEOUT` when that value
+is unset or zero. They do not use `DATA_CACHE_CONFIG["CACHE_DEFAULT_TIMEOUT"]` for this
+fallback, so setting only that nested default to `-1` does not disable these endpoints.
+With caching disabled, each request fetches fresh values or compatibility results from the source.
+
+This bypass does not delete existing entries. Earlier versions could write entries without
+expiry on Redis while the timeout was `-1`; column-value entries can become readable again
+when caching is re-enabled unless the datasource has been edited. Compatibility keys include
+the datasource modification time, matching column-value keys. Adding this key component makes
+older compatibility entries unreachable and causes a one-time cache miss for compatibility lists.
+Before re-enabling, invalidate affected `col_values:` entries through your deployment's
+cache-management tooling. Obsolete `compatible:` entries can also be removed to reclaim space.
+Account for your configured cache-key prefix when managing either kind of entry.
+
Native filter option queries (the dropdown values for native filters) go through this same
chart-data cache, but their freshness needs often differ from regular chart queries, especially for
datasets whose visible values change frequently, including RLS-constrained datasets. Set
diff --git a/superset/datasource/api.py b/superset/datasource/api.py
index 20c4c03414b..d2f3dd62d17 100644
--- a/superset/datasource/api.py
+++ b/superset/datasource/api.py
@@ -37,6 +37,7 @@ from superset.common.tabular_query import (
validate_query_names,
)
from superset.connectors.sqla.models import BaseDatasource
+from superset.constants import CACHE_DISABLED_TIMEOUT
from superset.daos.datasource import DatasourceDAO
from superset.daos.exceptions import DatasourceNotFound, DatasourceTypeNotSupportedError
from superset.datasource.schemas import DatasourceQuerySchema
@@ -148,8 +149,15 @@ def get_cached_column_values(
"q": search,
},
)
+ timeout: int = datasource.cache_timeout or app.config.get(
+ "CACHE_DEFAULT_TIMEOUT", 300
+ )
cached: list[Any] | None
- if not force and (cached := cache_manager.data_cache.get(cache_key)) is not None:
+ if (
+ timeout != CACHE_DISABLED_TIMEOUT
+ and not force
+ and (cached := cache_manager.data_cache.get(cache_key)) is not None
+ ):
logger.debug(
"column-values cache HIT: uid=%s col=%s", datasource.uid, column_name
)
@@ -177,13 +185,11 @@ def get_cached_column_values(
warn_threshold,
)
- timeout: int = datasource.cache_timeout or app.config.get(
- "CACHE_DEFAULT_TIMEOUT", 300
- )
# Bound each distinct search term's lifetime instead of retaining one
# entry per keystroke for the full default timeout.
timeout = min(timeout, SEARCH_CACHE_TIMEOUT) if search else timeout
- cache_manager.data_cache.set(cache_key, payload, timeout=timeout)
+ if timeout != CACHE_DISABLED_TIMEOUT:
+ cache_manager.data_cache.set(cache_key, payload, timeout=timeout)
logger.debug("column-values cache MISS: uid=%s col=%s", datasource.uid, column_name)
return payload, False
@@ -721,6 +727,7 @@ class DatasourceRestApi(BaseSupersetApi):
json.dumps(
{
"uid": datasource_uid,
+ "changed_on": str(getattr(datasource, "changed_on", "")),
"metadata_version": metadata_version,
"m": sorted(selected_metrics),
"d": sorted(selected_dimensions),
@@ -730,7 +737,14 @@ class DatasourceRestApi(BaseSupersetApi):
).hexdigest()
)
- if (cached := cache_manager.data_cache.get(cache_key)) is not None:
+ timeout: int = datasource.cache_timeout or app.config.get(
+ "CACHE_DEFAULT_TIMEOUT", 300
+ )
+ cached: dict[str, list[str]] | None
+ if (
+ timeout != CACHE_DISABLED_TIMEOUT
+ and (cached := cache_manager.data_cache.get(cache_key)) is not None
+ ):
return self.response(200, result=cached)
try:
@@ -745,10 +759,8 @@ class DatasourceRestApi(BaseSupersetApi):
except AmbiguousDimensionError as ex:
return self.response(400, message=str(ex))
- timeout = datasource.cache_timeout or app.config.get(
- "CACHE_DEFAULT_TIMEOUT", 300
- )
- cache_manager.data_cache.set(cache_key, result, timeout=timeout)
+ if timeout != CACHE_DISABLED_TIMEOUT:
+ cache_manager.data_cache.set(cache_key, result, timeout=timeout)
return self.response(200, result=result)
diff --git a/tests/unit_tests/semantic_layers/execution_context_test.py b/tests/unit_tests/semantic_layers/execution_context_test.py
index a0bc07e814c..1fafe9d6067 100644
--- a/tests/unit_tests/semantic_layers/execution_context_test.py
+++ b/tests/unit_tests/semantic_layers/execution_context_test.py
@@ -100,7 +100,8 @@ def test_connection_credentials_keys_unchanged(
keys.append(chart_key)
assert keys == [
"col_values:eb5d43a7322c2a03556fc53bc62d54fbbe0b3d26d561d18a0e385c7457abd822",
- "compatible:d073f97791e47e1308e077288564234b3e01e7452a065ba9dd52df2005463762",
+ # Compatibility identity includes changed_on="None" for this view.
+ "compatible:a2e526c4cd1db4f68fd34cc7dffe06cc4fbd029975f2147b4b11bb55179795b8",
# Recorded on master ffee0a843f: #45133 adds semantic-null-filters-v1
# to chart keys; the execution-context contract adds no discriminator.
"80b906df8cf7f4837b95d21c32c6f71bd6c810fcf7c1896dbeca74a5023ea961",
diff --git a/tests/unit_tests/semantic_layers/values_endpoint_test.py b/tests/unit_tests/semantic_layers/values_endpoint_test.py
index 0a5cab87980..ff5358e85c3 100644
--- a/tests/unit_tests/semantic_layers/values_endpoint_test.py
+++ b/tests/unit_tests/semantic_layers/values_endpoint_test.py
@@ -22,6 +22,7 @@ values, search pass-through, the 400 naming an unknown column, and the cache
header contract.
"""
+from datetime import datetime
from typing import Any, cast
from unittest.mock import MagicMock
@@ -581,6 +582,189 @@ def test_unversioned_suggestion_cache_material_is_unchanged(
assert keys[0] == keys[1]
+@pytest.mark.parametrize("use_default", [False, True])
+@pytest.mark.parametrize("warm", [False, True])
+@pytest.mark.parametrize("force", [False, True])
+@pytest.mark.parametrize("search", [False, True])
+def test_disabled_values_cache_skips_reads_and_writes(
+ client: Any,
+ full_api_access: None,
+ semantic_view_datasource: SemanticView,
+ mocker: MockerFixture,
+ use_default: bool,
+ warm: bool,
+ force: bool,
+ search: bool,
+) -> None:
+ """A disabled effective timeout bypasses warm and cold suggestion caches."""
+ from flask import current_app
+
+ from superset.constants import CACHE_DISABLED_TIMEOUT
+
+ semantic_view_datasource.cache_timeout = (
+ None if use_default else CACHE_DISABLED_TIMEOUT
+ )
+ mocker.patch.dict(
+ current_app.config,
+ {"CACHE_DEFAULT_TIMEOUT": CACHE_DISABLED_TIMEOUT if use_default else 300},
+ )
+ cache: MagicMock = mocker.patch("superset.datasource.api.cache_manager").data_cache
+ cache.get.return_value = ["stale"] if warm else None
+ response: Any = _get(
+ client,
+ f"category/values/?force={str(force).lower()}" + ("&q=oo" if search else ""),
+ )
+
+ assert response.status_code == 200
+ assert response.json["result"] == ["Books", "Clothing"]
+ assert response.headers["X-Cache-Status"] == "MISS"
+ cache.get.assert_not_called()
+ cache.set.assert_not_called()
+ implementation: MagicMock = cast(MagicMock, semantic_view_datasource.implementation)
+ implementation.get_values.assert_called_once()
+
+
+@pytest.mark.parametrize("use_default", [False, True])
+@pytest.mark.parametrize("warm", [False, True])
+def test_disabled_compatible_cache_skips_reads_and_writes(
+ client: Any,
+ full_api_access: None,
+ semantic_view_datasource: SemanticView,
+ mocker: MockerFixture,
+ use_default: bool,
+ warm: bool,
+) -> None:
+ """A disabled compatibility cache must recompute even with a stored result."""
+ from flask import current_app
+
+ from superset.constants import CACHE_DISABLED_TIMEOUT
+
+ semantic_view_datasource.cache_timeout = (
+ None if use_default else CACHE_DISABLED_TIMEOUT
+ )
+ mocker.patch.dict(
+ current_app.config,
+ {"CACHE_DEFAULT_TIMEOUT": CACHE_DISABLED_TIMEOUT if use_default else 300},
+ )
+ metrics: MagicMock = mocker.patch.object(
+ SemanticView, "get_compatible_metrics", return_value=["revenue"]
+ )
+ dimensions: MagicMock = mocker.patch.object(
+ SemanticView, "get_compatible_dimensions", return_value=["category"]
+ )
+ cache: MagicMock = mocker.patch("superset.datasource.api.cache_manager").data_cache
+ cache.get.return_value = {"stale": True} if warm else None
+
+ response: Any = client.post(
+ "/api/v1/datasource/semantic_view/1/compatible", json={}
+ )
+
+ assert response.status_code == 200
+ assert response.json["result"] == {
+ "compatible_metrics": ["revenue"],
+ "compatible_dimensions": ["category"],
+ }
+ metrics.assert_called_once_with([], [])
+ dimensions.assert_called_once_with([], [])
+ cache.get.assert_not_called()
+ cache.set.assert_not_called()
+
+
+@pytest.mark.parametrize("compatible", [False, True])
+@pytest.mark.parametrize(
+ "datasource_timeout, default_timeout, expected_timeout",
+ [(120, 300, 120), (None, 300, 300), (0, 300, 300), (120, -1, 120), (None, 0, 0)],
+)
+def test_enabled_suggestion_caches_preserve_timeout_and_hits(
+ client: Any,
+ full_api_access: None,
+ semantic_view_datasource: SemanticView,
+ mocker: MockerFixture,
+ compatible: bool,
+ datasource_timeout: int | None,
+ default_timeout: int,
+ expected_timeout: int,
+) -> None:
+ """Explicit/default timeout selection and warm hits remain unchanged."""
+ from flask import current_app
+
+ semantic_view_datasource.cache_timeout = datasource_timeout
+ mocker.patch.dict(current_app.config, {"CACHE_DEFAULT_TIMEOUT": default_timeout})
+ mocker.patch.object(SemanticView, "get_compatible_metrics", return_value=[])
+ mocker.patch.object(
+ SemanticView, "get_compatible_dimensions", return_value=["category"]
+ )
+ cache: MagicMock = mocker.patch("superset.datasource.api.cache_manager").data_cache
+ cache.get.return_value = None
+ response: Any = (
+ client.post("/api/v1/datasource/semantic_view/1/compatible", json={})
+ if compatible
+ else _get(client, "category/values/")
+ )
+ assert response.status_code == 200
+ cache.get.assert_called_once()
+ cache.set.assert_called_once()
+ assert cache.set.call_args.kwargs["timeout"] == expected_timeout
+ cache.get.return_value = response.json["result"]
+ cache.reset_mock()
+ cached_response: Any = (
+ client.post("/api/v1/datasource/semantic_view/1/compatible", json={})
+ if compatible
+ else _get(client, "category/values/")
+ )
+ assert cached_response.status_code == 200
+ assert cached_response.json["result"] == response.json["result"]
+ cache.get.assert_called_once()
+ cache.set.assert_not_called()
+
+
+def test_compatible_cache_invalidates_after_datasource_edit(
+ client: Any,
+ full_api_access: None,
+ semantic_view_datasource: SemanticView,
+ mocker: MockerFixture,
+) -> None:
+ """Unedited datasources hit warm entries; edited ones recompute compatibility."""
+ semantic_view_datasource.cache_timeout = 300
+ semantic_view_datasource.changed_on = datetime(2026, 1, 1)
+ metrics: MagicMock = mocker.patch.object(
+ SemanticView, "get_compatible_metrics", return_value=["old_metric"]
+ )
+ dimensions: MagicMock = mocker.patch.object(
+ SemanticView, "get_compatible_dimensions", return_value=["category"]
+ )
+ entries: dict[str, dict[str, list[str]]] = {}
+
+ def write_entry(key: str, value: dict[str, list[str]], timeout: int) -> None:
+ entries[key] = value
+
+ cache: MagicMock = mocker.patch("superset.datasource.api.cache_manager").data_cache
+ cache.get.side_effect = entries.get
+ cache.set.side_effect = write_entry
+ endpoint: str = "/api/v1/datasource/semantic_view/1/compatible"
+ response: Any = client.post(endpoint, json={})
+ assert response.status_code == 200
+ assert response.json["result"]["compatible_metrics"] == ["old_metric"]
+ first_key: str = cache.get.call_args.args[0]
+ cached_response: Any = client.post(endpoint, json={})
+ assert cached_response.status_code == 200
+ assert cached_response.json == response.json
+ assert cache.get.call_args.args[0] == first_key
+ metrics.assert_called_once()
+ dimensions.assert_called_once()
+ cache.set.assert_called_once()
+
+ semantic_view_datasource.changed_on = datetime(2026, 1, 2)
+ metrics.return_value = ["new_metric"]
+ edited_response: Any = client.post(endpoint, json={})
+ assert edited_response.status_code == 200
+ assert edited_response.json["result"]["compatible_metrics"] == ["new_metric"]
+ assert cache.get.call_args.args[0] != first_key
+ assert metrics.call_count == 2
+ assert dimensions.call_count == 2
+ assert cache.set.call_count == 2
+
+
def test_ambiguous_values_are_a_400_without_query_or_cache_write(
client: FlaskClient,
full_api_access: None,