[Bug] /api/v1/chart/warm_up_cache generates different cache keys than runtime - Filter Order Mismatch
#42382
Replies: 2 comments
|
Hi @curiousnihilist! I'm Dosu and I'm helping the Apache Superset team. Your analysis is solid. I can confirm the two root causes you identified: 1. Native filters not handled: 2. Filter order affects cache keys: A note on the specific code location: the current Regarding your questions:
Also worth noting: issue #34837 highlights a broader challenge — cache warmup runs under a system user context, so if Row-Level Security (RLS) is enabled, cache keys will still differ per user regardless of filter order fixes. Something to keep in mind if RLS is part of your setup. To reply, just mention @dosu. Share context across your team and agents. Try Dosu. |
|
Confirmed this is real, verified both root causes myself against current Also found something useful for whoever picks up the fix: there's already a correct native-filter extractor wired into the real Opened a test-only PR pinning the native-filter part of this: #43025. Left the filter-order part (your Option A/B) as a follow-up once that's fixed, since both need to land for warming to actually work. |
Uh oh!
There was an error while loading. Please reload this page.
Summary
The
/api/v1/chart/warm_up_cacheendpoint fails to effectively warm cache for charts on dashboards with native filters. Even when providingextra_filtersparameter, the generated cache keys differ from those produced at runtime by/api/v1/chart/data.Environment
Root Cause Analysis
I've identified two root causes for the cache key mismatch:
1. Native Filters Not Extracted
get_dashboard_extra_filters()insuperset/views/utils.py:332only reads legacydefault_filters, notnative_filter_configuration:Impact: Charts with native filter defaults get different filter values during warmup vs runtime.
2. Filter Order Mismatch
Even when
extra_filtersare provided, they're appended to the filter list via.extend(), but browsers send native filters first:Warmup code (line 101 in warm_up_cache.py):
Result:
Since
QueryObject.cache_key()hashes the filter list as-is, different order → different MD5 hash → cache miss.Reproduction Steps
extra_filtersmatching native filter defaultsHow to Verify
extra_filterscache_keyin/api/v1/chart/dataresponse vs warmupVerified Fix
I've tested and confirmed the fix works:
The Fix (one line change in
superset/commands/chart/warm_up_cache.pyline 101):Result: After applying this fix, both warmup and runtime endpoints generate identical cache keys, and
is_cached: Trueis returned confirming cache hit.Proposed Solutions
Option A: Prepend filters instead of append (Recommended)
In
superset/commands/chart/warm_up_cache.pyline 101, change:Option B: Sort filters before hashing
In
QueryObject.cache_key(), sort filters by column name before hashing to make order irrelevant.Workaround
Currently, the only reliable warmup method is:
/api/v1/chart/dataThis is not ideal for production environments.
Related Issues
Questions
Labels to add:
bug,caching,apiAll reactions