Skip to content

fix(cachekey): use data_cache for chart query result invalidation#40493

Open
Abdulrehman-PIAIC80387 wants to merge 1 commit into
apache:masterfrom
Abdulrehman-PIAIC80387:fix/cachekey-invalidate-uses-data-cache-40489
Open

fix(cachekey): use data_cache for chart query result invalidation#40493
Abdulrehman-PIAIC80387 wants to merge 1 commit into
apache:masterfrom
Abdulrehman-PIAIC80387:fix/cachekey-invalidate-uses-data-cache-40489

Conversation

@Abdulrehman-PIAIC80387
Copy link
Copy Markdown
Contributor

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:

-            all_keys_deleted = cache_manager.cache.delete_many(*cache_keys)
+            all_keys_deleted = cache_manager.data_cache.delete_many(*cache_keys)

TESTING INSTRUCTIONS

pytest tests/integration_tests/cachekeys/api_tests.py -v

Manual reproduction (per the issue)

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

@dosubot dosubot Bot added api Related to the REST API change:backend Requires changing the backend infra:caching Infra setup and configuration related to caching labels May 28, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 28, 2026

Code Review Agent Run #4ae5e8

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 4477d70..4477d70
    • superset/cachekeys/api.py
    • tests/integration_tests/cachekeys/api_tests.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.17%. Comparing base (c73106b) to head (4477d70).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #40493   +/-   ##
=======================================
  Coverage   64.17%   64.17%           
=======================================
  Files        2592     2592           
  Lines      139299   139299           
  Branches    32347    32347           
=======================================
  Hits        89395    89395           
  Misses      48367    48367           
  Partials     1537     1537           
Flag Coverage Δ
hive 39.20% <0.00%> (ø)
mysql 58.70% <100.00%> (ø)
postgres 58.78% <100.00%> (ø)
presto 40.88% <0.00%> (ø)
python 60.34% <100.00%> (ø)
sqlite 58.43% <100.00%> (ø)
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API change:backend Requires changing the backend infra:caching Infra setup and configuration related to caching size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /api/v1/cachekey/invalidate doesn't delete Redis entries when DATA_CACHE_CONFIG uses a different CACHE_KEY_PREFIX than CACHE_CONFIG

1 participant