Abdulrehman-PIAIC80387 opened a new pull request, #40493:
URL: https://github.com/apache/superset/pull/40493

   ### SUMMARY
   
   Fixes #40489. `POST /api/v1/cachekey/invalidate` was calling 
`cache_manager.cache.delete_many(...)` (which uses 
`CACHE_CONFIG.CACHE_KEY_PREFIX`), but the chart query results tracked by 
`CacheKey` rows are written via `cache_manager.data_cache` 
(`DATA_CACHE_CONFIG.CACHE_KEY_PREFIX`).
   
   When a deployment configures the two caches with different prefixes (the 
recommended multi-cache setup), `delete_many` issues `DEL` against the wrong 
Redis prefix and silently misses every key. The metadata rows are cleared, but 
Redis keeps serving stale chart data until TTL expiry. The mismatch is 
invisible in default-config deployments because both prefixes resolve to the 
same value.
   
   ### Fix
   
   One-line backend change in `superset/cachekeys/api.py`:
   
   ```diff
   -            all_keys_deleted = cache_manager.cache.delete_many(*cache_keys)
   +            all_keys_deleted = 
cache_manager.data_cache.delete_many(*cache_keys)
   ```
   
   ### TESTING INSTRUCTIONS
   
   ```bash
   pytest tests/integration_tests/cachekeys/api_tests.py -v
   ```
   
   - Existing tests updated to write/read via `cache_manager.data_cache` (they 
previously exercised the buggy path; `cache` and `data_cache` resolve to the 
same backend in the default test config so the asserts passed anyway).
   - New regression test `test_invalidate_uses_data_cache_not_default_cache` 
patches both `cache_manager.data_cache.delete_many` and 
`cache_manager.cache.delete_many`, then asserts the API calls the **data** 
cache and never touches the default cache — this is the precise condition 
#40489 fails on in production.
   
   ### Manual reproduction (per the issue)
   
   ```python
   CACHE_CONFIG      = {"CACHE_TYPE": "RedisCache", "CACHE_KEY_PREFIX": 
"superset_", ...}
   DATA_CACHE_CONFIG = {"CACHE_TYPE": "RedisCache", "CACHE_KEY_PREFIX": 
"superset_data_", ...}
   ```
   
   1. View a chart so it caches a result. `redis-cli EXISTS 
superset_data_<hash>` → `1`.
   2. `POST /api/v1/cachekey/invalidate {"datasource_uids":["<uid>"]}` → `201`.
   3. **Before fix:** `redis-cli EXISTS superset_data_<hash>` → still `1` 
(chart serves stale data).
   4. **After fix:** `redis-cli EXISTS superset_data_<hash>` → `0` (chart 
re-runs fresh query).
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: #40489
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to