Skip to content
Myr

Use setdefault() because it sets session.modified correctly.

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

authored by florentx · committed by Armin Ronacher · parent 3eacc1d · Browse files · 2 files+14 added−2 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+14 added−2 removed

  • tests:+12 added−0 removed
  • other:+2 added−2 removed

2 files+14 added−2 removed

modified:tests/flask_tests.py+12 added
115 unmodified lines
116 assert flask.session.get('missing_key') is None117 expect_exception(flask.session.__setitem__, 'foo', 42)118 expect_exception(flask.session.pop, 'foo')119120 def test_flashes(self):121 app = flask.Flask(__name__)122 app.secret_key = 'testkey'123124 with app.test_request_context():125 assert not flask.session.modified126 flask.flash('Zap')127 flask.session.modified = False128 flask.flash('Zip')129 assert flask.session.modified130 assert list(flask.get_flashed_messages()) == ['Zap', 'Zip']131132 def test_request_processing(self):133 app = flask.Flask(__name__)134 evts = []135 @app.before_request
181 unmodified lines
modified:flask.py+2 added-2 removed
165 unmodified lines
166 the template has to call :func:`get_flashed_messages`.167168 :param message: the message to be flashed.169 """170 session['_flashes'] = session.get('_flashes', ()) + (message,)170 session.setdefault('_flashes', []).append(message)171172173def get_flashed_messages():174 """Pulls all flashed messages from the session and returns them.
1 unmodified line
176 the same messages.177 """178 flashes = _request_ctx_stack.top.flashes179 if flashes is None:180 _request_ctx_stack.top.flashes = flashes = session.pop('_flashes', ())180 _request_ctx_stack.top.flashes = flashes = session.pop('_flashes', [])181 return flashes182183184def jsonify(*args, **kwargs):
617 unmodified lines