pallets-eco / pallets-eco/flask-debugtoolbar

Registered blueprint name does not match route blueprint name

Open
#177 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
978
Forks
151
PR merge metrics
No merged PRs in 30d

Description

The blueprint name registered for the app doesn't match that registered for the route.

The app is registered with blueprint name debubtoolbar

module = Blueprint('debugtoolbar', __name__)

But the route is registered with blueprint name _debug_toolbar as implied by the endpoint name _debug_toolbar.static. Thus, in a consuming app, flask.request.blueprint returns _debug_toolbar, which does not exist in flask.current_app.blueprints.

app.add_url_rule('/_debug_toolbar/static/<path:filename>',
                         '_debug_toolbar.static', self.send_static_file)

Three potential fixes - both simple, but may break existing consumers

  • Change the registered BP name to _debug_toolbar
  • Change the endpoint to use the BP name debugtoolbar, and then change the two references of url_for

Ideally in both cases, you'd register the route under the context of the BP to avoid the issue going forward. For example, if you use the second solution

module.add_url_rule('/_debug_toolbar/static/<path:filename>', endpoint="static", view_func=self.send_static_file)

References in url_for, for context:

toolbar.py

self.template_context = {
  'static_path': url_for('debugtoolbar.static', filename='')
}

panels/template.py

'static_path': url_for('debugtoolbar.static', filename=''),

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the blueprint registration and the static route shown in the issue, then inspect the url_for references in toolbar.py and panels/template.py. Choose a consistent blueprint and endpoint naming approach, account for compatibility, and verify that request.blueprint matches an entry in current_app.blueprints and that both static URLs resolve.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
backend, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.