Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[bug] CLI does not work correctly with Flask #946

@COUR4G3

Description

@COUR4G3

Describe the bug
When FLASK_APP is set in the environment then the CLI attempts to load the configuration from the Flask application. However an application is not detected - even if the environment variable is correctly set and works with the flask CLI command.

It appears an attempt was made to fix a similar issue in #705 (fixed in #774) however at least in my current environment and with the latest versions of Flask and Dynaconf (2.3.2 and 3.1.12 respectively at the time of this post) it does not seem to find the Flask application.

To Reproduce
Steps to reproduce the behavior:

  1. Set the FLASK_APP environment variable
export FLASK_APP=myapp:app
  1. Execute one of the Dynaconf CLI commands
dynaconf list

Expected behavior
The command should be executed, loading the configuration instance from the Flask application.

The fix?

It looks like:

https://github.com/obaranov/dynaconf/blob/8dbff540ed935b6cd26008e67d0a1266d2b8472e/dynaconf/cli.py#L56

is a bare instantiation of ScriptInfo, and app_import_path is never set. In Flask's own code:

https://github.com/pallets/flask/blob/cb825687a592709f902f3d320d93987a0546fd28/src/flask/cli.py#L393

the variable is being set with a callback on the app command-line option which then will result in being set from FLASK_APP. Since this code branch relies on the environment variable being set, I don't see why we can't just pass it here.

I'll make a pull request shortly.

Unless -i is to become a compulsory option, the we might need to update the syntax to support callables/factories with :

Environment (please complete the following information):

  • OS: Linux/Ubuntu20.04
  • Dynaconf: 3.1.12
  • Flask: 2.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions