Skip to content

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

Open
equivalent wants to merge 1 commit intoDavyJonesLocker:masterfrom
equivalent:to_hash_on_session
Open

suport for ActionDispatch::Request::Session as session object#113
equivalent wants to merge 1 commit intoDavyJonesLocker:masterfrom
equivalent:to_hash_on_session

Conversation

@equivalent
Copy link
Copy Markdown
Contributor

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
Copy link
Copy Markdown
Contributor Author

anyone have any opinion on this ?

@snatchev
Copy link
Copy Markdown

snatchev commented Apr 2, 2015

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

@defeated
Copy link
Copy Markdown
Contributor

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

@equivalent
Copy link
Copy Markdown
Contributor Author

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

@jmorais
Copy link
Copy Markdown

jmorais commented Sep 20, 2015

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants