Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add cache panel regression for skipped JSON keys
  • Loading branch information
puneetdixit200 committed May 23, 2026
commit 06b487aae82858bcc280ce4f55d0a7678a338b68
19 changes: 19 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import re
import time
import unittest
import warnings
from unittest.mock import patch

import html5lib
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core import signing
from django.core.cache import cache
from django.core.cache.backends.base import CacheKeyWarning
from django.db import connection
from django.http import HttpResponse
from django.template.loader import get_template
Expand Down Expand Up @@ -209,6 +211,23 @@ def test_low_level_cache_view(self):
len(response.toolbar.get_panel_by_id(CachePanel.panel_id).calls), 1
)

def test_cache_panel_store_skips_non_json_keys(self):
cache.clear()
with warnings.catch_warnings():
warnings.simplefilter("ignore", CacheKeyWarning)
response = self.client.get("/cache_with_non_json_key/")

self.assertEqual(response.status_code, 200)
self.assertEqual(
len(response.toolbar.get_panel_by_id(CachePanel.panel_id).calls), 1
)

request_id = list(get_store().request_ids())[-1]
toolbar = DebugToolbar.fetch(request_id, CachePanel.panel_id)
stats = toolbar.get_panel_by_id(CachePanel.panel_id).get_stats()
self.assertEqual(stats["calls"][0]["name"], "set_many")
self.assertEqual(stats["calls"][0]["args"], [{"foo": "bar"}])

def test_cache_disable_instrumentation(self):
"""
Verify that middleware cache usages before and after
Expand Down
1 change: 1 addition & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
path("async_execute_sql_concurrently/", views.async_execute_sql_concurrently),
path("cached_view/", views.cached_view),
path("cached_low_level_view/", views.cached_low_level_view),
path("cache_with_non_json_key/", views.cache_with_non_json_key_view),
path("json_view/", views.json_view),
path("redirect/", views.redirect_view),
path("ajax/", views.ajax_view),
Expand Down
5 changes: 5 additions & 0 deletions tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def cached_low_level_view(request):
return render(request, "base.html")


def cache_with_non_json_key_view(request):
cache.set_many({str: "this-is-a-string", "foo": "bar"})
return render(request, "base.html")


def json_view(request):
return JsonResponse({"foo": "bar"})

Expand Down
Loading