party_foul icon indicating copy to clipboard operation
party_foul copied to clipboard

suport for ActionDispatch::Request::Session as session object

Open equivalent opened this issue 11 years ago • 5 comments

in Rails 4 env['rack.session'] is ActionDispatch::Request::Session object => doesn't respond to #each 2

   13: def session
    14:   parameter_filter = ActionDispatch::Http::ParameterFilter.new(env['action_dispatch.parameter_filter'])
    15: 
 => 16:   binding.pry
    17: 
    18:   env_session = begin
    19:     env['rack.session'].to_hash
    20:   rescue NoMethodError
    21:     env['rack.session'] || { }
    22:   end
    23: 
    24:   parameter_filter.filter(env_session)
    25: end

[4] pry(#<PartyFoul::IssueRenderers::Rails>)> env['rack.session'].respond_to?(:each)
=> false
[5] pry(#<PartyFoul::IssueRenderers::Rails>)> env['rack.session'].class
=> ActionDispatch::Request::Session

# so :

[6] pry(#<PartyFoul::IssueRenderers::Rails>)> parameter_filter.filter(env['rack.session'])
NoMethodError: undefined method `each' for #<ActionDispatch::Request::Session:0x000000023718e0>
from /home/tomi/.rvm/gems/ruby-2.1.2@validations/gems/actionpack-4.0.9/lib/action_dispatch/http/parameter_filter.rb:51:in `

# but

[7] pry(#<PartyFoul::IssueRenderers::Rails>)> parameter_filter.filter(env['rack.session'].to_hash)
=> {"session_id"=>"df7cf659a9c513ed84a496b747132319 ..... 

equivalent avatar Oct 23 '14 14:10 equivalent

anyone have any opinion on this ?

equivalent avatar Dec 11 '14 11:12 equivalent

:+1: We've been experiencing a lot of "silent errors" due to this issue.

snatchev avatar Apr 02 '15 16:04 snatchev

We just ran into this.

For posterity, here is how bugsnag solved the same problem (slightly different approach, doesn't use exception handling as flow control):

https://github.com/bugsnag/bugsnag-ruby/pull/152/files

defeated avatar May 11 '15 21:05 defeated

do guys want me to rewrite this to if statements ? or is the exception capturing ok ?

equivalent avatar Jul 10 '15 10:07 equivalent

+1

jmorais avatar Sep 20 '15 02:09 jmorais