-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
Calling flash
after get_flashed_messages
fails
#5458
Comments
What does "off the rails" mean? Did an error happen? Be sure to provide a minimal reproducible example and the full traceback when reporting an issue. |
Sure, fair: from flask import Flask, flash, get_flashed_messages
app = Flask(__name__)
app.secret_key = "abcdef"
@app.route("/")
def hello_world():
get_flashed_messages()
flash("hi")
assert get_flashed_messages() Run with
go to http://127.0.0.1:5000/ and see
"Off the rails" means that |
This is documented: https://flask.palletsprojects.com/en/3.0.x/api/#flask.get_flashed_messages
The intended use is documented as well: https://flask.palletsprojects.com/en/3.0.x/patterns/flashing/
You're intended to put messages into one request, then get them out in the next request. Getting them out, putting them in, and getting them out again in the same request is not the intended use case. |
In a single request, do this:
get_flashed_messages()
flash(...)
get_flashed_messages()
again, observe that it returns the empty list, despite a message just having been flashed.After the first call to
get_flashed_messages()
,request_ctx.flashes
is[]
, which appears to send this code inget_flashed_messages
off the rails:flask/src/flask/helpers.py
Lines 364 to 367 in 98a7f9f
Environment:
The text was updated successfully, but these errors were encountered: