Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

SqlBypass session store doesn't use ActiveRecord::Base connection

#2383

All the methods in ActiveRecord::SessionStore::SqlBypass use @@connection class var, instead of the homonym class method. This of course doesn't not guarantee that var isn't nil.

Try it by yourself:

@@@ruby

config/initializers/session_store.rb

ActionController::Base.session_store = :active_record_store ActiveRecord::SessionStore.session_class = ActiveRecord::SessionStore::SqlBypass



Then try to start the server and use sessions, it should raise a `NoMethodError`.

I created a patch for solving this issue, but not the whole problem. Since there aren't unit tests for `ActiveRecord` session stores, but only functional tests in `ActionPack`.

As you can see from the patch I replaced `@@connection` with `connection` only where covered by tests.

Reported by Luca Guidi · March 31st, 2009 @ 03:52 PM

State: resolved
Milestone: 2.x
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Michael Koziarski
    Michael Koziarski
    • State changed from new to resolved

    April 11th, 2009 @ 10:16 AM

  2. Grant Hutchins
    Grant Hutchins
    • Tag cleared.
    • Assigned user set to Michael Koziarski

    Excuse me if I'm wrong, but was it a mistake to mark this ticket resolved?

    I am still seeing the issue that the original reporter describes, and it has been impeding my ability to use SqlBypass in my application.

    November 25th, 2009 @ 12:21 AM

  3. Luca Guidi
  4. Grant Hutchins
    Grant Hutchins

    I'm using Rails 2.3.5 (and was on 2.3.4 when I wrote the previous comment).

    I think I've figured out what's going on. The patch you mentioned fixes the issue for the find_by_session_id method, but I was running into problems with the other methods, which still use @@connection.

    I'll look into writing a patch.

    December 3rd, 2009 @ 05:43 PM

  5. Chris Pruett
    Chris Pruett

    I patched the code to use connection instead of @@connection, which fixed the issue for the first call to session. However, on subsequent requests, I receive this error:

    Mysql::Error: query: not connected: SELECT * FROM sessions WHERE session_id='1338b0600b1eddf9871f1fb878ac9bff'

    Patching the connection method to this seems to fix the issue, but I'm not sure why or if it's the right solution

    def connection
      @@connection = ActiveRecord::Base.connection
    end
    

    January 15th, 2010 @ 09:46 PM