Skip to content
Myr

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

2 files+22 added−9 removed

modified:flask/cli.py+19 added-9 removed
39 unmodified lines
40 if isinstance(app, Flask):41 return app4243 # 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 ]4748 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 )5657 # Search for app factory callables.58 for attr_name in 'create_app', 'make_app':59 app_factory = getattr(module, attr_name, None)6061 if callable(app_factory):62 try:63 app = app_factory()6465 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 )7475 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 )808182def prepare_exec_for_file(filename):83 """Given a filename this will try to calculate the python path, add it
524 unmodified lines
modified:CHANGES+3 added
38 unmodified lines
39 (`#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`_)4546.. _#1489: https://github.com/pallets/flask/pull/148947.. _#1898: https://github.com/pallets/flask/pull/189848.. _#1936: https://github.com/pallets/flask/pull/1936
2 unmodified lines
51.. _#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/22975657Version 0.12.258--------------59
615 unmodified lines