Flash bug or feature?

Hi,

As the subject suggests, I’m not sure if this is a bug or a feature.

If I have an action that sets something in the flash and redirects to
an
action
(to pre-empt the “flash.now” responses) that renders something
but does
not touch the flash at all
then the values will remain in the flash for
following requests to pick up. This could potentially be an infinite
number
of requests later if none of the requests in between touch the flash.

I believe this is because Request.flash is lazily loaded
https://github.com/rails/rails/blob/e6d8f435a921dce360bce9faae7dabaf753d4d23/actionpack/lib/action_dispatch/middleware/flash.rb#L9
but
only swept (as a side effect of to_session_value
https://github.com/rails/rails/blob/e6d8f435a921dce360bce9faae7dabaf753d4d23/actionpack/lib/action_dispatch/middleware/flash.rb#L103)
if it has been lazy loaded
https://github.com/rails/rails/blob/e6d8f435a921dce360bce9faae7dabaf753d4d23/actionpack/lib/action_dispatch/middleware/flash.rb#L269
.

Touching the flash in anyway (even without using it) will produce the
behaviour I expect of the flash being cleared in the request following
the
redirect and so no further requests being able to access it. This means
I
can use an after_action or similar to ensure it is always loaded and get
the behaviour I expect.

Is the current behaviour expected?

If it is, I have a work around and hopefully this will exist on Google
for
other people who expect it to work as I do. If it isn’t, I’m happy to
look
into it and create a pull request.

Cheers,
Garry

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs