Skip to content

Handle non-JSON mapping keys in toolbar storage - #2376

Merged
tim-schilling merged 2 commits into
django-commons:mainfrom
puneetdixit200:fix-store-skip-non-json-keys
May 25, 2026
Merged

Handle non-JSON mapping keys in toolbar storage#2376
tim-schilling merged 2 commits into
django-commons:mainfrom
puneetdixit200:fix-store-skip-non-json-keys

Conversation

@puneetdixit200

Copy link
Copy Markdown
Contributor

Description

Fixes #2189.

Toolbar storage now passes skipkeys=True to JSON serialization so panel data containing non-JSON-compatible mapping keys is stored without raising a server error. Valid JSON-compatible keys in the same data remain serialized. This follows the maintainer suggestion on the issue and adds coverage in SerializationTestCase.test_serialize_unexpected.

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

AI/LLM details: OpenAI GPT-5 assisted with the patch and validation.

Tests

  • UV_CACHE_DIR=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.uv-cache UV_PROJECT_ENVIRONMENT=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.venv uv run --group dev make test TEST_ARGS=tests.test_store.SerializationTestCase
  • UV_CACHE_DIR=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.uv-cache UV_PROJECT_ENVIRONMENT=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.venv uv run --group dev make test TEST_ARGS=tests.test_store
  • UV_CACHE_DIR=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.uv-cache UV_PROJECT_ENVIRONMENT=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.venv uv run --group dev make test
  • UV_CACHE_DIR=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.uv-cache UV_PROJECT_ENVIRONMENT=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.venv-ruff uv run --with ruff ruff check debug_toolbar/store.py tests/test_store.py
  • UV_CACHE_DIR=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.uv-cache UV_PROJECT_ENVIRONMENT=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.venv-ruff uv run --with ruff ruff format --check debug_toolbar/store.py tests/test_store.py
  • UV_CACHE_DIR=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.uv-cache UV_PROJECT_ENVIRONMENT=/Users/deepakkudi23/ai-resume-contrib-100/django-debug-toolbar/.venv uv run --group dev black --check debug_toolbar/store.py tests/test_store.py
  • git diff --check

@matthiask

Copy link
Copy Markdown
Member

Thanks!

It would be nice to have a test which actually goes through the cache panel (or some other panel) and shows how it handles things (better).

@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  debug_toolbar
  store.py
Project Total  

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

@puneetdixit200

Copy link
Copy Markdown
Contributor Author

This is covered now by tests.test_integration.DebugToolbarTestCase.test_cache_panel_store_skips_non_json_keys in 06b487a. The test goes through the cache panel via the /cache_with_non_json_key/ view, fetches the stored toolbar stats, and asserts the recorded set_many call keeps the JSON-compatible key while skipping the non-JSON key.

Rechecked locally:

  • uv run --group dev make test TEST_ARGS=tests.test_integration.DebugToolbarTestCase.test_cache_panel_store_skips_non_json_keys
  • uv run --group dev make test TEST_ARGS=tests.test_store.SerializationTestCase.test_serialize_unexpected
  • pre-commit run ruff --files debug_toolbar/store.py tests/test_store.py tests/test_integration.py tests/views.py tests/urls.py
  • pre-commit run ruff-format --files debug_toolbar/store.py tests/test_store.py tests/test_integration.py tests/views.py tests/urls.py

@matthiask matthiask left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think this looks good.

@tim-schilling
tim-schilling merged commit ad88086 into django-commons:main May 25, 2026
29 checks passed
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.

Store's JSON serialization breaks when keys aren't JSON compatible

3 participants