ActiveRecord and memory_store sessions error

It seems that memory_store sessions have problems storing ActiveRecord
The following test application work perfectly with the standard
session option (Rails 2.0.2) but if I add
config.action_controller.session_store = :memory_store
to envirnment.rb, I get the following error when I refresh the page:

SystemStackError in Unit#index
Showing unit/index.rhtml where line #1 raised:

stack level too deep

Extracted source (around line #1):

1: <p><%= %></p>
2: <p><%= @unit.description %></p>

I've found this ticket dating back to 2006 that seems to report a
similar problem:

Any idea other than adopting a different session option ?

Many thanks in advance.

Brubix wrote:

model unit.rb
class Unit < ActiveRecord::Base

controller unit_controller.rb
class UnitController < ApplicationController

  def index
    if session[:currentUnit]
      @unit = session[:currentUnit]
      @unit = Unit.find(:first)
      session[:currentUnit] = @unit


view index.rhtml
<p><%= %></p>
<p><%= @unit.description %></p>

I don't think you want to be storing the whole object to session.

def index
  if session[:current_unit_id]
    @unit = Unit.find(session[:current_unit_id])
    @unit = Unit.find(:first)
    session[:current_unit_id] =

but you'd probably prefer to do it with a before_filter.

Thank you for your answer.
Could you please illustrate it in a little more detail ?

In the real application I'm working on, changes to the current unit
may occur in more than one user interaction and are not necessarily
comitted to the db at the end of work.

Of course I can switch to a different session engine (what I already
did) or change the application logic but still my questions are:
- is this the expected behavior of the :memory_store or is it a bug ?
- is there something I should check or set to change this behavior ?