Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError (no _dump_data is defined for class Proc):

I am trying to store a value in the session using the below code in my rails application

session[:key] = value 

And i get the below error

TypeError (no _dump_data is defined for class Proc):
activesupport (3.2.9) lib/active_support/message_verifier.rb:53:in `dump'
 activesupport (3.2.9) lib/active_support/message_verifier.rb:53:in `generate'
 actionpack (3.2.9) lib/action_dispatch/middleware/cookies.rb:300:in `[]='
actionpack (3.2.9) lib/action_dispatch/middleware/session/cookie_store.rb:67:in    `set_cookie'
rack (1.4.1) lib/rack/session/abstract/id.rb:330:in `commit_session'
rack (1.4.1) lib/rack/session/abstract/id.rb:206:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.9) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.9)    lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `

Any help is highly appreciated.

like image 471
Bindesh Vijayan Avatar asked Dec 13 '12 14:12

Bindesh Vijayan


3 Answers

In my case, we were caching an ActiveRecord model and that model had an @ variable that contained a lambda function. That was causing the issue.

like image 138
Shankar Thyagarajan Avatar answered Sep 21 '22 10:09

Shankar Thyagarajan


Your value is either a Proc or has s Proc nested inside of it somewhere. Procs and lambdas cannot be serialized/marshaled/dumped because they are closures. Closures depend on what is in memory at the time they are created, and therefore cannot be unserialized correctly later.

See this answer.

I'm not sure what I will be doing in my case, it looks like I will have to figure out a way to accomplish my task without relying on Procs.

like image 6
changokun Avatar answered Oct 24 '22 04:10

changokun


What is this value? Is it a complicated object? An active record instance maybe?

I had the same problem trying to put an FourSquare client object into the session. I've changed to create a new instance every time, instead of recovering from session, and it worked ok.

like image 2
André Onuki Avatar answered Oct 24 '22 05:10

André Onuki