Skip to content

Fix incorrect cache hit/miss reporting for cache.get()#2418

Open
Harsh3006 wants to merge 3 commits into
django-commons:mainfrom
Harsh3006:fix-cache-get-hit-miss
Open

Fix incorrect cache hit/miss reporting for cache.get()#2418
Harsh3006 wants to merge 3 commits into
django-commons:mainfrom
Harsh3006:fix-cache-get-hit-miss

Conversation

@Harsh3006

@Harsh3006 Harsh3006 commented Jul 15, 2026

Copy link
Copy Markdown

Description

This change fixes incorrect cache hit/miss reporting in the Cache panel for cache.get().

Previously, the Cache panel determined whether a cache.get() call was a hit or a miss solely based on whether the returned value was None. This resulted in two incorrect scenarios:

A missing key with a supplied default (for example, cache.get("missing", "default")) was reported as a cache hit, even though the value was not retrieved from the cache.
A cached value of None was reported as a cache miss, even though the key existed in the cache.

The Cache panel now correctly distinguishes between a missing cache key and a cached value equal to the caller's supplied default while preserving the existing cache.get() behavior.

Fixes #2417

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

AI/LLM Usage

  • This PR includes code generated with the help of an AI/LLM

@Harsh3006
Harsh3006 force-pushed the fix-cache-get-hit-miss branch 2 times, most recently from 8f05493 to 13bc758 Compare July 15, 2026 19:50
@Harsh3006
Harsh3006 force-pushed the fix-cache-get-hit-miss branch from 13bc758 to 7af7a62 Compare July 15, 2026 19:56
@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  debug_toolbar/panels
  cache.py 127, 166-167
Project Total  

This report was generated by python-coverage-comment-action

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache panel incorrectly reports hits and misses for cache.get() when a default value is supplied or None is cached

1 participant