This project is archived and is in readonly mode.

#6527 new
cschiefelbein

validate_uniqueness_of (2.3.5) with scoping broken against PostgreSQL 9.0

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

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

No comments found

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

Pages