Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Server command ignores some values in config associated with app #108

Open

Description

@dlipovetsky

Running the below code with Flask 0.10.1 and Flask-Script 2.0.5 will result in a server starting at port 5000, though the app is explicitly configured to use port 8888. To the end user, the SERVER_NAME configuration value appears to be ignored.

from flask import Flask
from flask.ext.script import Manager

app = Flask(__name__)
app.config['SERVER_NAME'] = 8888
manager = Manager(app)

if __name__ == '__main__':
    manager.run()

As of 0.10, Flask parses SERVER_NAME to set the host and port, falling to defaults if not set. (https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L823)

Server command sets its own defaults (https://github.com/smurfix/flask-script/blob/master/flask_script/commands.py#L339) and initializes app with them (https://github.com/smurfix/flask-script/blob/master/flask_script/commands.py#L417), so the end result is an app that has all configuration settings, but some are not applied.

I'm not sure if this behavior merits changing. However, I think it should be documented, since it is confuses the end user when certain configuration values (e.g. SERVER_NAME) appear to be ignored.

Activity

  1. nfvs commented on Dec 10, 2014

    @nfvs
    Contributor

    This seems to have been fixed at some point, although Flask requires SERVER_NAME to be a string, setting it to an int throws an exception in Flask, setting it without a host makes it be ignored.

  2. tdeck commented on Jul 26, 2015

    @tdeck

    I am just starting with Flask-Script and am experiencing the same issue. It looks like runserver calls app.run like this:

            app.run(host=host,
                    port=port,
                    debug=use_debugger,
                    use_debugger=use_debugger,
                    use_reloader=use_reloader,
                    threaded=threaded,
                    processes=processes,
                    passthrough_errors=passthrough_errors,
                    **self.server_options)
    

    with default values for host, port, etc... This overrides all the normal flask configuration environment variables, which is pretty frustrating to work around.

  3. tdeck commented on Jul 27, 2015

    @tdeck

    In case anyone else lands on this, I've found a workaround that works in the specific case of SERVER_NAME, which is simply to make my own runserver command that goes back to providing Nones for host= and port= like so:

    ...
    manager = Manager(app)
    manager.add_command(
        "runserver",
        flask_script.commands.Server(host=None, port=None)
    )

    This will cause Flask to use whatever fallback it chooses, which will be the environment, then Flask's own internal defaults.

  4. ariscn commented on Oct 21, 2015

    @ariscn

    +1, just bit by this.

    Thanks for the workaround, @tdeck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions