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.

double bind variable expansion in activerecord condtions

#6281

When specifying the table name in an ActiveRecord model scope, the bind variables expansion runs when it should not:

>> Action.scoped(:conditions => {:actions => {:message => ["is this fun?", "hats are nice"]}})
ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (0 for 1) in: `actions`.`message` IN ('is this fun?','hats are nice')

These forms all work as expected:

>> # no question mark
>> Action.scoped(:conditions => {:actions => {:message => ["is this fun", "hats are nice"]}})
Action Load (1.0ms)  SELECT * FROM `actions` WHERE (`actions`.`message` IN ('is this fun','hats are nice'))

>> # no table name
>> Action.scoped(:conditions => {:message => ["is this fun?", "hats are nice"]})
Action Load (1.0ms)  SELECT * FROM `actions` WHERE (`actions`.`message` IN ('is this fun?','hats are nice'))

>> # no nesting
>> Action.scoped(:conditions => {"actions.message" => ["is this fun?", "hats are nice"]})
Action Load (1.0ms)  SELECT * FROM `actions` WHERE (`actions`.`message` IN ('is this fun?','hats are nice'))

I believe the problem is that sanitize_sql_hash_for_conditions calls itself recursively after generating the table name, and expand_range_bind_variables is called twice instead of once as it unwinds.

https://github.com/rails/rails/blob/2-3-stable/activerecord/lib/act...
https://github.com/rails/rails/blob/2-3-stable/activerecord/lib/act...

Reported by Greg Hazel · January 12th, 2011 @ 12:06 PM

State: open
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. rails
    rails
    • Tag changed from rails 2.3.10, 2.3.10, activerecord, conditions to rails 2310, 2310, activerecord, conditions
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    April 13th, 2011 @ 01:00 AM

  2. rails
    rails
    • State changed from open to stale

    April 13th, 2011 @ 01:00 AM

  3. Greg Hazel
    Greg Hazel
    • Tag changed from rails 2310, 2310, activerecord, conditions to rails 2.3.11, 2.3.11, activerecord, conditions
    • State changed from stale to open

    [state:open]

    April 13th, 2011 @ 05:17 AM