This project is archived and is in readonly mode.
validates_uniqueness_of does not quote scoped column names and then barfs
Reported by ara.t.howard | June 20th, 2010 @ 01:33 AM | in 2.3.9
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
Comments and changes to this ticket
-
Santiago Pastorino June 20th, 2010 @ 01:38 AM
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 ;). -
José Valim June 22nd, 2010 @ 04:39 PM
- Milestone cleared.
- Assigned user changed from Santiago Pastorino to José Valim
-
ara.t.howard June 22nd, 2010 @ 04:42 PM
i won't have time to work up tests for a bit, but haven't forgotten.
-
Neeraj Singh June 22nd, 2010 @ 06:54 PM
I believe this is no longer an issue in rails edge. Howard can you verify that.
-
Kane June 22nd, 2010 @ 07:09 PM
also think this is no longer an issue. edge uses arel where clause for the scopes and no longer string concatination.
-
José Valim June 22nd, 2010 @ 08:46 PM
- State changed from new to resolved
Confirmed, thanks guys!
-
ara.t.howard June 22nd, 2010 @ 08:47 PM
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.
-
José Valim June 22nd, 2010 @ 08:51 PM
- Milestone set to 2.3.9
- State changed from resolved to new
Oh right, swapping for 2.3.
-
José Valim June 23rd, 2010 @ 08:17 AM
Kane, your patch broke other tests on AR suite. Could you please take a look at them? Thanks!
-
Neeraj Singh June 23rd, 2010 @ 11:04 AM
Attached are the patches for the tests which were failing by applying the patch.
-
Neeraj Singh June 23rd, 2010 @ 11:08 AM
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.
-
Repository June 23rd, 2010 @ 04:39 PM
- State changed from new to resolved
(from [09a23d22908813f4b572d8c676325a12c51cfa9a]) quote scoped columns in validates_uniqueness_of [#4909 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/09a23d22908813f4b572d8c676325a... -
ara.t.howard June 23rd, 2010 @ 07:47 PM
thanks for that guys. a small but nasty bug when it hits.
cheers.
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
Attachments
Referenced by
- 4945 add column named 'group' to Topic model in ActiveRecord test as discussed in #4909
- 4909 validates_uniqueness_of does not quote scoped column names and then barfs (from [09a23d22908813f4b572d8c676325a12c51cfa9a]) quote s...