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.

validate_uniqueness_of (2.3.5) with scoping broken against PostgreSQL 9.0

#6527

validate_uniqueness_of does not quote scoped values when constructing the SQL query, so if the scoped column happens to be text, you get a PGError. (PostgreSQL 8.2 server did not complain)

class Group < ActiveRecord::Base

  # name, section, and subsection are all text columns
  validates_uniqueness_of :name, :scope => [:section, :subsection]

end

class GroupTest < ActiveSupport::TestCase
  # blows up with PGError
  should validate_uniqueness_of(:name).scoped_to([:section, :subsection])
end

Here is the specific error from the database:

ActiveRecord::StatementInvalid: PGError: ERROR:  operator does not exist: character varying = integer
LINE 1: ..."groups"."name" = E'09-01' AND "groups".section = 1 AND "g...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

I have written a patch against ActiveRecord::Validations (see attached). I would gladly write tests too, but I'm running on Gentoo, which does not know about libxml2-dev or libxslt1-dev, and "gem install bundler" is timing out right now, too. So I don't have a formal test setup (but my patch works in the above case).

Reported by cschiefelbein · March 4th, 2011 @ 08:24 PM

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

Activity

No comments yet.