Repository navigation
feat(gaq): minimum result-cache TTL for async chart-data queries - #43463
Conversation
Async chart data caches each query's result and the client then re-issues the
request to read it back, so a cache TTL shorter than that round trip could evict
the result before it is fetched, hanging the chart. Add
GLOBAL_ASYNC_QUERIES_MIN_CACHE_TTL (default 5 min): when a query runs async, its
result-cache TTL is floored to this value.
The floor is applied in QueryContextProcessor.get_cache_timeout, gated on an
is_async_execution flag set only by the async task (execute_chart_query), so
synchronous /chart/data requests are never affected even when GLOBAL_ASYNC_QUERIES
is enabled. A longer slice/dataset/deployment timeout is kept as-is, and 0
("cache forever") is left untouched.
|
Bito Automatic Review Skipped - Branch Excluded |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
/review |
| if 0 < timeout < min_ttl: | ||
| return min_ttl | ||
| return timeout |
There was a problem hiding this comment.
Suggestion: The post-resolution floor also applies to NATIVE_FILTER_OPTIONS_CACHE_TIMEOUT, despite that timeout being an independent freshness policy for native filter option queries. An async native-filter request configured with a short value such as 30 seconds will be cached for 300 seconds and can serve stale filter values. Exclude native filter option queries from this floor or apply the floor before selecting their dedicated timeout. [cache]
Severity Level: Major ⚠️
- ⚠️ Native filter options remain stale beyond configured freshness.
- ⚠️ RLS-constrained filter values can remain outdated.
- ⚠️ Dashboard filter controls may show unavailable values.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/common/query_context_processor.py
**Line:** 621:623
**Comment:**
*Cache: The post-resolution floor also applies to `NATIVE_FILTER_OPTIONS_CACHE_TIMEOUT`, despite that timeout being an independent freshness policy for native filter option queries. An async native-filter request configured with a short value such as 30 seconds will be cached for 300 seconds and can serve stale filter values. Exclude native filter option queries from this floor or apply the floor before selecting their dedicated timeout.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Good catch — valid and reachable. Native filter option queries can run on the async path (FilterValue.tsx passes async_mode_override), so flooring their dedicated NATIVE_FILTER_OPTIONS_CACHE_TIMEOUT to the async minimum would serve stale (and potentially RLS-constrained) filter values for the floor's duration.
Fixed in 9a1b0d3cf5: _resolve_cache_timeout now reports whether the resolved timeout is floorable, and the native-filter-options branch returns floorable=False so get_cache_timeout skips the floor for it. Added test_async_native_filter_options_query_is_not_floored (30s stays 30s on the async path). The general result-cache timeouts (steps 3–5) and explicit custom_cache_timeout still floor, since those results genuinely need to survive the async cache→read-back round trip.
| # Floor the result-cache TTL: async caches the result for a follow-up | ||
| # request to read back (see get_cache_timeout). | ||
| query_context.is_async_execution = True |
There was a problem hiding this comment.
Suggestion: Setting is_async_execution does not ensure that the cache entry is written with the floored TTL. If the initial cache miss races with another request that populates the same key, get_df_payload_result will accept that existing entry and skip set_query_result, leaving its original short expiration. The follow-up request can then miss the cache and schedule another query. The async task should refresh or rewrite the entry using the async timeout when it finds an existing result. [race condition]
Severity Level: Major ⚠️
- ❌ Async chart re-fetch can miss completed results.
- ⚠️ Identical queries may be scheduled repeatedly.
- ⚠️ Users can see delayed or failed chart rendering.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/tasks/async_queries.py
**Line:** 125:127
**Comment:**
*Race Condition: Setting `is_async_execution` does not ensure that the cache entry is written with the floored TTL. If the initial cache miss races with another request that populates the same key, `get_df_payload_result` will accept that existing entry and skip `set_query_result`, leaving its original short expiration. The follow-up request can then miss the cache and schedule another query. The async task should refresh or rewrite the entry using the async timeout when it finds an existing result.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
The mechanism is correct — on a cache hit get_df_payload_result skips set_query_result, so an entry another request populated with a short TTL keeps that TTL — but in practice this is low-severity and self-healing, so I've left it as-is:
- Async vs. async can't race. Each
QueryObjectruns as a SHARED GTF task keyed byquery_cache_key, so concurrent async requests for the same key dedup to one task. There is no second async writer. - The only race is async-task vs. a concurrent sync request (sync never floors). For it to actually cause a re-fetch miss, the sync-written TTL must expire in the window between the async task observing the hit and the client re-issuing — roughly one poll interval (~0.5–1s). Only a pathologically sub-second
DATA_CACHETTL would bite. - It self-heals. On a re-request miss the async flow just schedules the query again and succeeds on the next round; it degrades to one extra round trip, not a hang.
Re-setting the TTL on every async cache hit would add a cache write to the hot path (flask-caching has no cheap "touch"/EXPIRE through QueryCacheManager) to cover a self-correcting sub-second edge case, which isn't a good trade. Happy to revisit if you'd prefer the guard.
| mocker.patch.dict(current_app.config, {"GLOBAL_ASYNC_QUERIES_MIN_CACHE_TTL": 300}) | ||
| # The floor applies only to async execution; a sync request keeps its timeout | ||
| # even when GLOBAL_ASYNC_QUERIES is enabled. |
There was a problem hiding this comment.
Suggestion: The test claims to verify synchronous behavior while GLOBAL_ASYNC_QUERIES is enabled, but it only patches the minimum TTL. If the implementation incorrectly floors synchronous requests whenever the global async feature is enabled, this test still passes because that feature remains at its default value. Patch GLOBAL_ASYNC_QUERIES to true in this test so the asserted sync-path gating is actually exercised. [incomplete implementation]
Severity Level: Minor 🧹
- ⚠️ Sync-path gating is not tested with async globally enabled.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/common/test_async_min_cache_ttl.py
**Line:** 64:66
**Comment:**
*Incomplete Implementation: The test claims to verify synchronous behavior while `GLOBAL_ASYNC_QUERIES` is enabled, but it only patches the minimum TTL. If the implementation incorrectly floors synchronous requests whenever the global async feature is enabled, this test still passes because that feature remains at its default value. Patch `GLOBAL_ASYNC_QUERIES` to true in this test so the asserted sync-path gating is actually exercised.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Fair — hardened in 9a1b0d3cf5. test_sync_execution_is_not_floored now patches FEATURE_FLAGS={"GLOBAL_ASYNC_QUERIES": True}, so the test proves the floor is gated on the execution mode (is_async_execution), not on the feature flag. If a future change accidentally gated on the flag instead, this test would now fail.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## gaq-to-gtf #43463 +/- ##
==============================================
- Coverage 78.86% 78.85% -0.01%
==============================================
Files 2883 2883
Lines 164782 164776 -6
Branches 38083 38084 +1
==============================================
- Hits 129949 129941 -8
- Misses 32388 32390 +2
Partials 2445 2445
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
SUMMARY
Targets
gaq-to-gtf. A short cache TTL can break the async chart-data flow: async runs each query, caches its result, and the client then re-issues the request to read it from cache. If the result-cache TTL is shorter than that round trip (task queue + execution + poll interval + re-request), the entry can be evicted before it's fetched, and the chart hangs / errors.Add
GLOBAL_ASYNC_QUERIES_MIN_CACHE_TTL(default 300s / 5 min): when a query runs on the async path, its result-cache TTL is floored to this value.QueryContextProcessor.get_cache_timeout, gated on anis_async_executionflag set only by the async task (execute_chart_query). Synchronous/chart/datarequests are never floored, even whenGLOBAL_ASYNC_QUERIESis enabled — as requested.0("cache forever" in flask-caching) is left untouched.TESTING INSTRUCTIONS
pytest tests/unit_tests/common/test_async_min_cache_ttl.py— async floors a short TTL (60→300), keeps a longer one (3600), leaves 0 untouched, and does not floor sync execution.pytest tests/unit_tests/common/test_query_context_processor.py tests/unit_tests/tasks/test_async_queries.py— unchanged behavior; mypy/ruff/pre-commit clean.ADDITIONAL INFORMATION
GLOBAL_ASYNC_QUERIES(the floor only applies on the async path)GLOBAL_ASYNC_QUERIES_MIN_CACHE_TTLconfig)