views:

151

answers:

1

(this is regarding the Ramaze.net framework)

I ran into some really strange problems while storing custom Objects in session. I noticed that only the attributes on the objects immediately stored in session were being updated. However, if those objects contained references to other objects, those referenced objects were not updated if the immediate objects contained in session did not change during the request.

This problem only became apparent to me when using Ramaze::FileCache as my session caching backend. I believe the problem is masked or not an issue when using in-memory sessions.

I discovered the problem is because of a "shallow copy" in the session logic found in Ramaze::Session::Hash#method_missing (lib/ramaze/current/session/hash.rb).

As a quick test to make sure my thinking was correct, I commented out the "difference check," essentially forcing session to be updated every time.

  def method_missing(*args, &block)
    old = @hash.dup
    result = @hash.send(*args, &block)
    #unless old == @hash
      Cache.sessions[@session.session_id] = self
    #end
    result
  end

This little hack fixed my problem. Now my questions are:

  1. is it a safe and reasonable solution?
  2. Should I just avoid storing complex/deep objects in session?
  3. Is there something I'm missing?
+1  A: 

This issue has been solved in latest Ramaze (2009.04), please file a patch at the Ramaze issue tracker if the problem persists.

manveru