Skip to content
Myr

push preserved contexts in correct order

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 5addaf8 · Browse files · 3 files+15 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+15 added−23 removed

  • tests:+10 added−21 removed
  • other:+5 added−2 removed

3 files+15 added−23 removed

modified:src/flask/testing.py+2 added-2 removed
238 unmodified lines
239 )240 response.json_module = self.application.json # type: ignore[assignment]241242 # Re-push contexts that were preserved during the request.243 while self._new_contexts:244 cm = self._new_contexts.pop()243 for cm in self._new_contexts:244 self._context_stack.enter_context(cm)245246 self._new_contexts.clear()247 return response248249 def __enter__(self) -> FlaskClient:250 if self.preserve_context:
48 unmodified lines
modified:tests/test_testing.py+10 added-21 removed
136 unmodified lines
137 rv = client.get("/", subdomain="xxx")138 assert rv.data == b"http://xxx.example.com:1234/foo/"139140141def test_redirect_keep_session(app, client, app_ctx):142 @app.route("/", methods=["GET", "POST"])141def test_redirect_session(app, client, app_ctx):142 @app.route("/redirect")143 def index():144 if flask.request.method == "POST":145 return flask.redirect("/getsession")146 flask.session["data"] = "foo"147 return "index"144 flask.session["redirect"] = True145 return flask.redirect("/target")146149 @app.route("/getsession")147 @app.route("/target")148 def get_session():151 return flask.session.get("data", "<missing>")149 flask.session["target"] = True150 return ""151152 with client:154 rv = client.get("/getsession")155 assert rv.data == b"<missing>"153 client.get("/redirect", follow_redirects=True)154 assert flask.session["redirect"] is True155 assert flask.session["target"] is True156157 rv = client.get("/")158 assert rv.data == b"index"159 assert flask.session.get("data") == "foo"157161 rv = client.post("/", data={}, follow_redirects=True)162 assert rv.data == b"foo"163 assert flask.session.get("data") == "foo"164165 rv = client.get("/getsession")166 assert rv.data == b"foo"167168158def test_session_transactions(app, client):159 @app.route("/")160 def index():161 return str(flask.session["foo"])
224 unmodified lines
modified:CHANGES.rst+3 added
1 unmodified line
2-------------34Unreleased56- When using ``follow_redirects`` in the test client, the final state7 of ``session`` is correct. :issue:`5786`8910Version 3.1.111-------------1213Released 2025-05-13
1609 unmodified lines