Skip to content

chore: gate Django debug toolbar behind DEBUG env in local settings - #9880

Merged
sriramveeraghanta merged 1 commit into
previewfrom
chore/local-debug-toolbar-env-flag
Sep 25, 2026
Merged

sriramveeraghanta merged 1 commit into
previewfrom
chore/local-debug-toolbar-env-flag

Conversation

@prateekshourya29

@prateekshourya29 prateekshourya29 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Description

The Django debug toolbar was unconditionally loaded in plane/settings/local.py, and its SQL panel captures a full Python stack trace for every query — even on JSON API responses where the toolbar UI never renders. On query-heavy endpoints this adds noticeable overhead to the local API.

This PR makes local settings rely on the existing DEBUG env var instead of hardcoding DEBUG = True:

  • local.py now reads DEBUG from the environment (default 1, so local setups behave as before)
  • Loads the debug_toolbar app, its middleware, and DEBUG_TOOLBAR_PATCH_SETTINGS only when DEBUG is on

Setting DEBUG=0 in the API environment disables the toolbar and its per-request overhead (__debug__/ routes in urls.py are already gated on settings.DEBUG and whether the app is installed). Only local development settings are affected; production settings are untouched.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

  • Start the local API with no DEBUG env var set — toolbar loads as before (DEBUG=True, toolbar in INSTALLED_APPS / middleware)
  • Start with DEBUG=0 — toolbar app/middleware absent; DEBUG_TOOLBAR_PATCH_SETTINGS unset
  • python manage.py check --settings=plane.settings.local passes with DEBUG set to both 0 and 1
  • Verified via settings introspection that settings.DEBUG, INSTALLED_APPS, and MIDDLEWARE toggle correctly with the env var

References

N/A

Port of makeplane/plane-ee#7664. Local settings now read DEBUG from the
environment (default on) and only load debug_toolbar when DEBUG is enabled,
so DEBUG=0 skips its per-request SQL/panel overhead.
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4e2a7312-a9f6-485d-b6bd-48d5cdfd462f

📥 Commits

Reviewing files that changed from the base of the PR and between c2b0ecd and 6b5ced6.

📒 Files selected for processing (1)
  • apps/api/plane/settings/local.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Local settings now read DEBUG from the environment, defaulting to enabled when unset. Debug Toolbar registration and its patch-settings override occur only when DEBUG is enabled.

Changes

Local debug settings

Layer / File(s) Summary
Debug mode and toolbar registration
apps/api/plane/settings/local.py
DEBUG is enabled when the environment variable equals "1" and defaults to enabled when unset. Debug Toolbar registration and DEBUG_TOOLBAR_PATCH_SETTINGS = False are conditional on DEBUG.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 6b5ce

The change is mergeable based on the supplied evidence: local debug remains enabled when DEBUG is unset, and setting DEBUG=0 opts out of debug and the toolbar.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 6b5ce

The change lets local API operators turn off debug mode and the toolbar. It preserves the previous default and does not appear to add diagnostic exposure. Whether a local API is reachable beyond a developer machine depends on its deployment configuration.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Potential diagnostic-route exposure is limited to API instances explicitly using local settings with DEBUG enabled. The local server binds all interfaces, but the available evidence does not establish whether such an instance is externally reachable.

Trust Boundaries and Controls

  • observed — The toolbar route has two registration conditions—DEBUG and installed-app membership. The new local setting applies the environment choice to both conditions.

Hardening Proposals

  • proposed — For any local-settings instance reachable outside a trusted development network, set DEBUG=0 and restrict network access. This addresses the pre-existing default-on local configuration rather than a new exposure from this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: gating the Django debug toolbar behind the DEBUG environment variable in local settings.
Description check ✅ Passed The description follows the repository template. It explains the change, identifies the improvement and performance impact, lists test scenarios for DEBUG=0 and DEBUG=1, and addresses screenshots and …
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread apps/api/plane/settings/local.py Resolved
Comment thread apps/api/plane/settings/local.py Resolved
Comment thread apps/api/plane/settings/local.py Resolved
@sriramveeraghanta
sriramveeraghanta merged commit cffb82d into preview Sep 25, 2026
18 of 19 checks passed
@sriramveeraghanta
sriramveeraghanta deleted the chore/local-debug-toolbar-env-flag branch September 25, 2026 10:42
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.

2 participants