Skip to content

Commit

Permalink
fix(cache): respect default cache timeout on v1 chart data requests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored and AAfghahi committed Dec 15, 2022
1 parent 3653cd3 commit 292d1b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/superset-python-unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'requirements/testing.txt'
# TODO: separated requiermentes.txt file just for unit tests
# TODO: separated requirements.txt file just for unit tests
- name: Install dependencies
if: steps.check.outcome == 'failure'
uses: ./.github/actions/cached-dependencies
Expand Down
2 changes: 1 addition & 1 deletion scripts/python_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ superset init

echo "Running tests"

pytest --durations-min=2 --maxfail=1 --cov-report= --cov=superset "$@"
pytest --durations-min=2 --maxfail=1 --cov-report= --cov=superset ./tests/integration_tests "$@"
8 changes: 7 additions & 1 deletion superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,12 @@ class ChartDataQueryContextSchema(Schema):
query_context_factory: Optional[QueryContextFactory] = None
datasource = fields.Nested(ChartDataDatasourceSchema)
queries = fields.List(fields.Nested(ChartDataQueryObjectSchema))
custom_cache_timeout = fields.Integer(
description="Override the default cache timeout",
required=False,
allow_none=True,
)

force = fields.Boolean(
description="Should the queries be forced to load from the source. "
"Default: `false`",
Expand Down Expand Up @@ -1257,7 +1263,7 @@ class ChartDataResponseResult(Schema):
)
cache_timeout = fields.Integer(
description="Cache timeout in following order: custom timeout, datasource "
"timeout, default config timeout.",
"timeout, cache default timeout, config default cache timeout.",
required=True,
allow_none=True,
)
Expand Down
6 changes: 6 additions & 0 deletions superset/common/query_context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ def get_cache_timeout(self) -> int:
cache_timeout_rv = self._query_context.get_cache_timeout()
if cache_timeout_rv:
return cache_timeout_rv
if (
data_cache_timeout := config["DATA_CACHE_CONFIG"].get(
"CACHE_DEFAULT_TIMEOUT"
)
) is not None:
return data_cache_timeout
return config["CACHE_DEFAULT_TIMEOUT"]

def cache_key(self, **extra: Any) -> str:
Expand Down

0 comments on commit 292d1b6

Please sign in to comment.