Skip to content
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

Allow debugger to be controlled from application configuration #1641

Closed
nZac opened this issue Dec 6, 2015 · 6 comments
Closed

Allow debugger to be controlled from application configuration #1641

nZac opened this issue Dec 6, 2015 · 6 comments

Comments

@nZac
Copy link
Contributor

nZac commented Dec 6, 2015

I submitted a patch for this but learned that it was incomplete with further testing. #1640

Basically, it would be nice to allow DEBUG on the application to control the activation of the debugger and reloader when running the CLI like app.run does.

@Kareeeeem
Copy link

I'm surprised noone has replied to this. I was really confused about this due to the comments in the source code at https://github.com/mitsuhiko/flask/blob/master/flask/cli.py#L399-L400

The reloader and debugger are by default enabled if the debug flag of Flask is enabled and disabled otherwise.

That doesn't seem to be the case. The app is configured with DEBUG to True but it doesn't get picked up by the run command.

I ended up writing my cli entry point like this.

@click.group(cls=FlaskGroup, create_app=create_app)                                
@script_info_option('--config', script_info_key='config')                          
@pass_script_info                                                                  
def cli(info, **params):                                                           
    '''This is an entry point for scripts that require the app context.            
    '''                                                                            
    info.debug = info.load_app().config['DEBUG']

@dalai4git
Copy link

The workaround above did not work for me. In the run_command() the debug flag is enabled based on the return value of get_debug_flag() which in turn only depends on the environment.

This is what worked for me

@click.group(cls=FlaskGroup, create_app=create_app)
@pass_script_info
def cli(info):
    """This is the management script of the dzik application"""
    os.environ["FLASK_DEBUG"] = str(info.load_app().config['DEBUG'])

@untitaker
Copy link
Contributor

I think the behavior of flask run unconditionally overriding app.debug is completely intentional. It is not particularly convenient, but given that there's already such a complex dependency between app.debug, Jinja's auto_reload etc (see #1910 for just one example), I think this behavior is just easier to understand.

However, we definetly should provide a way to set FLASK_DEBUG from within your own CLI, no question about that.

@robkorv
Copy link

robkorv commented Oct 9, 2016

I just want to respond as a user in a story 🦄 that just did a hello world from the docs.

I expected that using DEBUG = True from http://flask.pocoo.org/docs/0.11/config/#configuration-best-practices would do the same as export FLASK_DEBUG=1 from http://flask.pocoo.org/docs/0.11/server/#command-line.

@john-bodley
Copy link

@dalai4git the FLASK_DEBUG environment needs to be either 0 or 1 rather than False or True and thus I think you additionally need to cast the DEBUG configuration variable to an int first, i.e.,

str(int(info.load_app().config['DEBUG']))

@davidism
Copy link
Member

davidism commented Jan 9, 2018

We do not plan to support this. Use FLASK_ENV=development to enable the development environment, or FLASK_DEBUG=1 to control debug mode.

@davidism davidism closed this as completed Jan 9, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants