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

Unable to find application in the module of a flask app, while using factory function to load app. The app runs fine while executing the app without debugging #705

Closed
DeathReaper0965 opened this issue Feb 5, 2018 · 6 comments
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@DeathReaper0965
Copy link

DeathReaper0965 commented Feb 5, 2018

Environment data

VS Code version: 1.19.3
Python Extension version: 2018.1.0
Python Version: 3.6
OS and version: Ubuntu 17.10

Actual behavior

Error: Failed to find application in module "run". Are you sure it contains a Flask application? Maybe you wrapped it in a WSGI middleware or you are using a factory function.

Expected behavior

The flask app to begin running a localhost server.

Steps to reproduce:

  • Install Visual Studio Code
  • Install python extension
  • Update launch.json with the correct pythonPath and program settings for python.exe and flask.exe, respectively
  • Debug -> Start Debugging
  • Select "Python: Flask (0.11.x or later)" as the configuration
  • Press F5
  • Error message is printed and debugger doesn't start

Settings

My launch.json "Python: Flask (0.11.x or later)" confugiration:

{
            "name": "Python: Flask (0.11.x or later)",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "${config:python.pythonPath}",
            "module": "flask",
            "cwd": "${workspaceRoot}",
            "env": {
                "FLASK_APP": "${workspaceFolder}/run.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "envFile": "${workspaceFolder}/.env",
            "debugOptions": [
                "RedirectOutput"
            ]
}

run.py file:

from module_test import create_app

if __name__ == '__main__':
    app = create_app('test', '')
    app.run(host='0.0.0.0', port=5000, debug=True)

__init.py__ file:

def create_app(config_file_name, chdir):
    app = Flask(__name__)
    return app

Logs

Output from Python output panel

Output from Console window (Help->Developer Tools menu)

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug awaiting 1-verification area-debugging labels Feb 5, 2018
@DonJayamanne
Copy link

Your sample code is incorrect, please try running it from outside vs code (e.g. in the terminal).
Here's a simple sample that will work:

from flask import Flask
app = Flask(__name__)


@app.route('/')
def hello():
    return "Hello World!"

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

@DeathReaper0965
Copy link
Author

That cannot be possible, I'm creating the "app" in another module where the "create_app" is defined. The "create_app" function creates an app instance with required parameters and returns the app. Moreover, it runs perfectly when executed, but it fails with the above mentioned error while debugging. I request you to please consider this again as it might be an issue.

@DonJayamanne DonJayamanne reopened this Feb 13, 2018
@DonJayamanne
Copy link

DonJayamanne commented Feb 13, 2018

  • Please could you provide the entire code sample so I could replicate this at my end.
    Or please upload the repo.

  • Moreover, it runs perfectly when executed

How are you executing this manually?
Have you tried configuring launch.json accordingly?

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed closed-invalid labels Feb 13, 2018
@DeathReaper0965
Copy link
Author

I edited the post, the init.py in the module contains my importing function "create_app".

How are you executing this manually?

I'm running it through the terminal inside VS Code.

Have you tried configuring launch.json accordingly?

Yes, I've even posted the configuration file above

@DonJayamanne
Copy link

Once again, Please could you provide the entire code sample so I could replicate this at my end. I don't know what your create_app looks like.

I'm running it through the terminal inside VS Code

Please provide the command executed in the terminal.

Yes, I've even posted the configuration file above

Please modify launch.json to match the command executed in the terminal window.

@brettcannon
Copy link
Member

Because it has been more than a month since we requested more info, I'm closing this issue. If you are able to provide the info later then please do so and we can re-open the issue.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants