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.

validates_uniqueness_of does not quote scoped column names and then barfs

#4909

column isn't quoted when it's from a scope column. this makes any reserved word liek 'group' blow up.

this is a silly bug that breaks any code where the column name of a
scope is a reserved word (like group):

cfp:/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8 > diff -buB
lib/active_record/validations.rb.org lib/active_record/validations.rb

--- lib/active_record/validations.rb.org        2010-06-19
09:38:42.000000000 -0600
+++ lib/active_record/validations.rb    2010-06-19 09:39:01.000000000
-0600
@@ -825,7 +825,7 @@
           if scope = configuration[:scope]
             Array(scope).map do |scope_item|
               scope_value = record.send(scope_item)
-              condition_sql << " AND " <<
attribute_condition("#{record.class.quoted_table_name}.#{scope_item}",
scope_value)
+              condition_sql << " AND " <<
attribute_condition("#{record.class.quoted_table_name}.#{connection.quote_column_name(scope_item)}",
scope_value)
               condition_params << scope_value
             end
           end

Reported by ara.t.howard · June 20th, 2010 @ 01:33 AM

State: resolved
Milestone: 2.3.9
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Santiago Pastorino
    Santiago Pastorino

    ara.t.howard please follow this to send us a patch https://rails.lighthouseapp.com/projects/8994/sending-patches
    Also you need to do a failing test case, i want to help you to get the patch applied ;).

    June 20th, 2010 @ 01:38 AM

  2. José Valim
    José Valim
    • Milestone cleared.
    • Assigned user changed from Santiago Pastorino to José Valim

    June 22nd, 2010 @ 04:39 PM

  3. ara.t.howard
    ara.t.howard

    i won't have time to work up tests for a bit, but haven't forgotten.

    June 22nd, 2010 @ 04:42 PM

  4. Neeraj Singh
    Neeraj Singh

    I believe this is no longer an issue in rails edge. Howard can you verify that.

    June 22nd, 2010 @ 06:54 PM

  5. Kane
    Kane

    also think this is no longer an issue. edge uses arel where clause for the scopes and no longer string concatination.

    June 22nd, 2010 @ 07:09 PM

  6. José Valim
    José Valim
    • State changed from new to resolved

    Confirmed, thanks guys!

    June 22nd, 2010 @ 08:46 PM

  7. ara.t.howard
    ara.t.howard

    just to be clear - this is and activerecord issue - not a 'rails' issue. moving to a rails milestone seems like a bad plan. for sure people will be using ar 2x for year(s) to come right? in fact, the project i'm seeing the issue in is a financial cli - not a rails app.

    June 22nd, 2010 @ 08:47 PM

  8. José Valim
    José Valim
    • Milestone set to 2.3.9
    • State changed from resolved to new

    Oh right, swapping for 2.3.

    June 22nd, 2010 @ 08:51 PM

  9. Kane
  10. José Valim
    José Valim

    Kane, your patch broke other tests on AR suite. Could you please take a look at them? Thanks!

    June 23rd, 2010 @ 08:17 AM

  11. Neeraj Singh
    Neeraj Singh

    Attached are the patches for the tests which were failing by applying the patch.

    June 23rd, 2010 @ 11:04 AM

  12. Neeraj Singh
    Neeraj Singh

    In rails3 Topics table does not have a column named 'group'.

    In my view it is a good idea to bring that column in rails3 Topic model to ensure that nothing breaks if a user decides to have a column named 'group'. José lemme know your thoughts. If needed I can create a patch for rails3 and add column 'group' to Topics.

    June 23rd, 2010 @ 11:08 AM

  13. José Valim
    José Valim

    Neeraj: about Rails 3, sounds good!

    June 23rd, 2010 @ 11:18 AM

  14. Repository
  15. ara.t.howard
    ara.t.howard

    thanks for that guys. a small but nasty bug when it hits.

    cheers.

    June 23rd, 2010 @ 07:47 PM