This project is archived and is in readonly mode.

#2383 ✓resolved
Luca Guidi

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

Reported by Luca Guidi | March 31st, 2009 @ 03:52 PM | in 2.x

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.

Comments and changes to this ticket

  • Michael Koziarski

    Michael Koziarski April 11th, 2009 @ 10:16 AM

    • State changed from “new” to “resolved”
  • Grant Hutchins

    Grant Hutchins November 25th, 2009 @ 12:21 AM

    • 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.

  • Luca Guidi
  • Grant Hutchins

    Grant Hutchins December 3rd, 2009 @ 05:43 PM

    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.

  • Chris Pruett

    Chris Pruett January 15th, 2010 @ 09:46 PM

    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
    

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages