Skip to content

Fix KeyError in DatabaseStore when dynamically adding panels and ensure from_store flag is set correctly #2184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abdibaker
Copy link
Contributor

@abdibaker abdibaker commented Aug 15, 2025

Description

This commit addresses the KeyError issue that occurs when using DatabaseStore with dynamically added panels to DEBUG_TOOLBAR_PANELS. The problem occurred in StoredDebugToolbar.from_store() where the method would only load panels that had stored data, causing a KeyError when accessing panels that were added after the initial request.

The fix modifies the panel loading logic to:

  1. Always load all configured panels regardless of stored data existence
  2. Properly set the from_store flag for panels that have stored data
  3. Maintain backward compatibility while ensuring graceful handling of missing panel data

This ensures that the toolbar works correctly when panels are dynamically added to the configuration, particularly when using DatabaseStore for persistent storage.

Fixes #2166

Checklist:

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

@abdibaker abdibaker changed the title Fix KeyError in DatabaseStore when dynamically adding panels and ensure from_store flag is set correctly #2183 Fix KeyError in DatabaseStore when dynamically adding panels and ensure from_store flag is set correctly Aug 15, 2025
The DatabaseStore fix caused all panels to be loaded, including disabled
ones like ProfilingPanel. The history sidebar was including all panels
in its JSON response rather than filtering by enabled status.

This change adds a check for panel.enabled in the history sidebar view
to ensure only enabled panels are included in the response, matching
the behavior expected by tests and consistent with the main toolbar
display logic.

Fixes failing tests:
- test_history_sidebar
- test_history_sidebar_expired_request_id
- test_history_sidebar_includes_history
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.

Gracefully handle panels that don't exist
1 participant