rails / protected_attributes

Protect attributes from mass-assignment in ActiveRecord models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined method `[]' for nil:NilClass

avitus opened this issue · comments

commented

I recently upgraded from Rails 4.0.0 to Rails 4.0.2 and simultaneously upgraded from protected_attributes 1.0.3 to 1.0.5.

When I try to access a column (string) in a model which has been retrieved from memcache via Rails.cache.fetch I get the following error in our production environment:

NoMethodError: undefined method `[]' for nil:NilClass

Oddly enough, this doesn't occur in our development environment or in the console in our production environment.

Below is the relevant portion of the stacktrace.

/gems/activerecord-4.0.2/lib/active_record/attribute_methods/read.rb:86 in "block in read_attribute"
/gems/activerecord-4.0.2/lib/active_record/attribute_methods/read.rb:84 in "fetch"
/gems/activerecord-4.0.2/lib/active_record/attribute_methods/read.rb:84 in "read_attribute"
/gems/activerecord-4.0.2/lib/active_record/attribute_methods/read.rb:59 in "__temp__4786f657768647"

the exception trace doesn't show anything in this gem, are you sure the problem is here?

commented

Yeah, sorry, just realized I posted in wrong place. I will delete.

@avitus I have this same error. My trace shows protected_attributes but maybe you already solved it somewhere else?

+1 I got the same. The app works without the gem, in rails 4, but adding gem 'protected_attributes' yields this error all over the place, no real stacktrace at all. rails 4.0.2, protected_attributes 1.0.3. I get the error on '= csrf_meta_tags' already, and all my specs. Just

NoMethodError: undefined method `[]' for nil:NilClass

Not sure where to look next.

@oma upgrade your protected_attributes gem

@rafaelfranca thanks, not sure why I had 1.0.3, I've been debugging for a while now, I'm back on

gem 'protected_attributes', github: 'rails/protected_attributes'

and this bug is gone. That brings me back to the original problem I had, that my sessions where broken. I found the solution to here: rails/activerecord-session_store#6