Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11443 (new enhancement)

Opened 5 months ago

Last modified 5 months ago

[PATCH] SqlBypass accesses class variable directly instead of accessor

Reported by: anthony_caliendo Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords:
Cc:

Description

Using the SqlBypass as a session store requires you to set the connection, even if you want to use the default connection. This issue was brought up in http://dev.rubyonrails.org/ticket/5490 , but the bug was resolved as "won't fix" because the proposed solution would always consume a database connection (even if the class was not used).

I have created a patch (with test) which proposes an alternate solution for this problem. In my solution, the code will use the default connection if it is not set when the #find_by_session_id method is invoked. The patch is simple, and just replaces direct access to the @@connection variable with a call to the connection method. This method already uses the default connection if not set, so the change in behavior makes the class act more consistent with itself. This allows the use of SqlBypass without the need to explicitly set the connection, but it will not make the database connection unless the class is actually used.

I have only patched #find_by_session_id because that change met my needs, but it might also be a good idea to change the other methods which access the class variable directly with calls to the method.

Attachments

sqlbypass#find_by_session_id-use_accessor_method.patch (1.6 kB) - added by anthony_caliendo on 03/27/08 15:48:26.
Patch (with test) so #find_by_session_id uses the accessor method

Change History

03/27/08 15:48:26 changed by anthony_caliendo

  • attachment sqlbypass#find_by_session_id-use_accessor_method.patch added.

Patch (with test) so #find_by_session_id uses the accessor method

03/27/08 15:51:06 changed by anthony_caliendo

  • summary changed from SqlBypass accesses class variable directly instead of accessor to [PATCH] SqlBypass accesses class variable directly instead of accessor.