Uploaded image for project: 'BrainzUtils'
  1. BrainzUtils
  2. BU-7

DebugToolbar won't load if CustomFlask created with no config

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 1.4.0
    • Python
    • None

      In BrainzUtils' CustomFlask we enable the flask debug toolbar if the parameter is set and DEBUG is true: https://github.com/metabrainz/brainzutils-python/blob/18229350b764201e966fb9d89784d4e2258a95c6/brainzutils/flask/__init__.py#L33-L34

      However, configuration in MeB projects typically isn't loaded until after the CustomFlask object is created (https://github.com/metabrainz/listenbrainz-server/blob/563e83ee88844f0d47f6af4514a659bfc396284e/listenbrainz/webserver/__init__.py#L43-L47). Debug toolbar also requires a SECRET_KEY to be set in the config, which means that it's important that we load config before loading the debug toolbar.

      Setting FLASK_DEBUG=1 when loading a project may result in:

      {{ File "/code/webserver/_init_.py", line 13, in create_app_with_configuration}}
      {{ use_debug_toolbar=True}}
      {{ File "/usr/local/lib/python2.7/site-packages/brainzutils/flask/_init.py", line 34, in __init_}}
      {{ DebugToolbarExtension(self)}}
      {{ File "/usr/local/lib/python2.7/site-packages/flask_debugtoolbar/_init.py", line 58, in __init_}}
      {{ self.init_app(app)}}
      {{ File "/usr/local/lib/python2.7/site-packages/flask_debugtoolbar/_init_.py", line 69, in init_app}}
      {{ "The Flask-DebugToolbar requires the 'SECRET_KEY' config "}}
      RuntimeError: The Flask-DebugToolbar requires the 'SECRET_KEY' config var to be set

       

      To fix this, we should remove the debug toolbar parameter from the CustomFlask constructor and add a separate method to install it that can be called after configuration is loaded.

            iliekcomputers Param Singh
            alastairp Alastair Porter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Version Package
                1.4.0