{"record":{"id":"f2c3c2b6f8f9a1aa","repo":"pallets/flask","slug":"detected-multiple-flask-applications-in-module-m","errorCode":null,"errorMessage":"Detected multiple Flask applications in module '{module.__name__}'. Use '{module.__name__}:name' to specify the correct one.","messagePattern":"Detected multiple Flask applications in module '(.+?)'\\. Use '(.+?):name' to specify the correct one\\.","errorType":"exception","errorClass":"NoAppException","httpStatus":null,"severity":"error","filePath":"src/flask/cli.py","lineNumber":60,"sourceCode":"    \"\"\"Given a module instance this tries to find the best possible\n    application in the module or raises an exception.\n    \"\"\"\n    from . import Flask\n\n    # Search for the most common names first.\n    for attr_name in (\"app\", \"application\"):\n        app = getattr(module, attr_name, None)\n\n        if isinstance(app, Flask):\n            return app\n\n    # Otherwise find the only object that is a Flask instance.\n    matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]\n\n    if len(matches) == 1:\n        return matches[0]\n    elif len(matches) > 1:\n        raise NoAppException(\n            \"Detected multiple Flask applications in module\"\n            f\" '{module.__name__}'. Use '{module.__name__}:name'\"\n            \" to specify the correct one.\"\n        )\n\n    # Search for app factory functions.\n    for attr_name in (\"create_app\", \"make_app\"):\n        app_factory = getattr(module, attr_name, None)\n\n        if inspect.isfunction(app_factory):\n            try:\n                app = app_factory()\n\n                if isinstance(app, Flask):\n                    return app\n            except TypeError as e:\n                if not _called_with_wrong_args(app_factory):\n                    raise","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/cli.py#L42-L78","documentation":"Raised by Flask's CLI app-discovery when scanning a module finds more than one Flask instance and neither is named app/application. The CLI cannot guess which app to use, so it requires an explicit FLASK_APP target.","triggerScenarios":"Setting FLASK_APP=module where module defines two or more Flask instances (e.g. app1 = Flask(...) and app2 = Flask(...)) and neither is named app or application.","commonSituations":"Multiple app instances in one module during refactor; legacy app alongside a new one; test fixtures that define extra Flask objects at module scope.","solutions":["Set FLASK_APP=module:app_name to point at the specific instance.","Rename the intended app to app or application so it is picked automatically.","Remove or move unrelated Flask instances out of the target module."],"exampleFix":"// before\n# myapp.py\napp1 = Flask(__name__)\napp2 = Flask(__name__)\n# FLASK_APP=myapp -> raises\n// after\n# export FLASK_APP=myapp:app1","handlingStrategy":"validation","validationCode":"apps = [v for v in module.__dict__.values() if isinstance(v, Flask)]\nif len(apps) > 1:\n    raise RuntimeError('Multiple apps; set FLASK_APP=module:name')","typeGuard":"import flask\ndef is_flask_app(obj) -> bool:\n    return isinstance(obj, flask.Flask)","tryCatchPattern":"try:\n    app = find_best_app(module)\nexcept NoAppException:\n    # require explicit FLASK_APP\n    raise","preventionTips":["Name the intended app app or application for auto-detection.","Set FLASK_APP=module:name explicitly when multiple apps exist.","Keep unrelated Flask instances out of the target module."],"tags":["cli","configuration","flask-app-env"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}