This project is archived and is in readonly mode.

#6281 open
Greg Hazel

double bind variable expansion in activerecord condtions

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

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

Comments and changes to this ticket

  • rails

    rails April 13th, 2011 @ 01:00 AM

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

  • rails

    rails April 13th, 2011 @ 01:00 AM

    • State changed from “open” to “stale”
  • Greg Hazel

    Greg Hazel April 13th, 2011 @ 05:17 AM

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

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>

People watching this ticket

Pages