show error if multiple Flask instances are detected
Before adoption: this commit came in with the history the project adopted, so no landing records it.
add changelog
authored by David Lord · committed by David Lord · parent b4eb653 · Browse files · 2 files·+22 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+22 added−9 removed
- other:+22 added−9 removed
Provenance
- Commit
7ecdbcf- Tree
d4989ba- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
b4eb653
2 files changed+22 added−9 removed
modified:flask/cli.py+19 added-9 removed
39 unmodified lines40 if isinstance(app, Flask):41 return app42 43 # Otherwise find the only object that is a Flask instance.44- matches = [v for k, v in iteritems(module.__dict__)45- if isinstance(v, Flask)]44+ matches = [45+ v for k, v in iteritems(module.__dict__) if isinstance(v, Flask)46+ ]47 48 if len(matches) == 1:49 return matches[0]50+ elif len(matches) > 1:51+ raise NoAppException(52+ 'Auto-detected multiple Flask applications in module "{module}".'53+ ' Use "FLASK_APP={module}:name" to specify the correct'54+ ' one.'.format(module=module.__name__)55+ )56 57 # Search for app factory callables.58 for attr_name in 'create_app', 'make_app':59 app_factory = getattr(module, attr_name, None)60+61 if callable(app_factory):62 try:63 app = app_factory()64+65 if isinstance(app, Flask):66 return app67 except TypeError:68 raise NoAppException(69 'Auto-detected "{callable}()" in module "{module}", but '61- 'could not call it without specifying arguments.'62- .format(callable=attr_name,63- module=module.__name__))70+ 'could not call it without specifying arguments.'.format(71+ callable=attr_name, module=module.__name__72+ )73+ )74 75 raise NoAppException(66- 'Failed to find application in module "{module}". Are you sure '67- 'it contains a Flask application? Maybe you wrapped it in a WSGI '68- 'middleware or you are using a factory function.'69- .format(module=module.__name__))76+ 'Failed to find application in module "{module}". Are you sure '77+ 'it contains a Flask application? Maybe you wrapped it in a WSGI '78+ 'middleware.'.format(module=module.__name__)79+ )80 81 82 def prepare_exec_for_file(filename):83 """Given a filename this will try to calculate the python path, add it524 unmodified linesmodified:CHANGES+3 added
38 unmodified lines39 (`#2282`_)40 - Allow IP address as exact session cookie domain. (`#2282`_)41 - ``SESSION_COOKIE_DOMAIN`` is set if it is detected through ``SERVER_NAME``.42 (`#2282`_)43+- Auto-detect 0-argument app factory called ``create_app`` or ``make_app`` from44+ ``FLASK_APP``. (`#2297`_)45 46 .. _#1489: https://github.com/pallets/flask/pull/148947 .. _#1898: https://github.com/pallets/flask/pull/189848 .. _#1936: https://github.com/pallets/flask/pull/19362 unmodified lines51 .. _#2254: https://github.com/pallets/flask/pull/225452 .. _#2256: https://github.com/pallets/flask/pull/225653 .. _#2259: https://github.com/pallets/flask/pull/225954 .. _#2282: https://github.com/pallets/flask/pull/228255+.. _#2297: https://github.com/pallets/flask/pull/229756 57 Version 0.12.258 --------------59 615 unmodified lines