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

Explain AssertionError on the new @setupmethod 'shell_context_processor' behavior #4869

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/appcontext.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ See :doc:`/reqcontext` for more information about how the contexts work
and the full life cycle of a request.


New @setupmethod behavior
-------------------------

Since Flask 2.2.0, the @setupmethod can only be called once per instance and requires therefore the Flask application object to be defined in a basic application factory such as ``create_app`` to support multiple instances of the same application running in the same application process.

See :doc:`/patterns/appfactories` for more information about how the application factories work.

Flask automatically *pushes* an app context when handling a request. Flask cannot handle a second request of the @setupmethod in the same instance. If the Flask application object is not defined in a app factory, Flask would raise an error on the @setupmethod 'shell_context_processor':

.. code-block:: pytb

AssertionError: The setup method 'shell_context_processor' can no
longer be called on the application. It has already handled its
first request, any changes will not be applied consistently. Make
sure all imports, decorators, functions, etc. needed to set up the
application are done before running it.


Manually Push a Context
-----------------------

Expand Down