#671 ✓resolved
Arthur Zapparoli

dm-validations do not checks for duplicated validations

Reported by Arthur Zapparoli | November 26th, 2008 @ 12:43 AM | in 0.10.0

Consider this code:


class Page
  include DataMapper::Resource

  property :id, Serial, :key => true
  property :body, Text, :nullable => false

  validates_present :body

end

It adds the same validation twice for the body. I know validates_present isn't necessary when :nullable => false is present, but it should not add the same validation twice, right?


>> Page.auto_migrate!
 ~ DROP TABLE IF EXISTS `pages`
 ~ SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_type` = 'BASE TABLE' AND `table_schema` = 'fooi_development' AND `table_name` = 'pages'
 ~ SHOW VARIABLES WHERE `variable_name` = 'character_set_connection'
 ~ SHOW VARIABLES WHERE `variable_name` = 'collation_connection'
 ~ CREATE TABLE `pages` (`id` INT NOT NULL AUTO_INCREMENT, `body` TEXT NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
=> true
>> p = Page.new
=> #<Page id=nil body=nil>
>> p.valid?
=> false
>> p.errors
=> #<DataMapper::Validate::ValidationErrors:0x237a134 @errors={:body=>["Body must not be blank", "Body must not be blank"]}>
>>

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 5th, 2008 @ 05:10 AM

    • Tag changed from bug, dm-validations, validations to bug, dm-more, dm-validations, validations
    • State changed from “new” to “confirmed”

    We should probably use a SortedSet to store all the validation rules to prevent duplicates from being inserted. This may also require the validation rules to have proper #hash and #eql? methods that actually can determine equivalency between the same rules.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 8th, 2009 @ 02:33 PM

    • State changed from “confirmed” to “unconfirmed”
    • Assigned user set to “Michael Klishin (antares)”

    Michael, when you get a moment, would you mind seeing if this is still a problem?

    FYI: I never mentioned this before, but whenever you accept a ticket to work on, can you change the status to "accepted" so that we know someone is working on it, or planning to work on it.

  • Michael Klishin (antares)

    Michael Klishin (antares) March 25th, 2009 @ 05:00 PM

    • Milestone set to 0.10.0
    • State changed from “unconfirmed” to “accepted”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) March 25th, 2009 @ 11:26 PM

    • State changed from “accepted” to “resolved”

    (from [21c8b6dd6c1b9b169e42859d002a05b331015536]) [dm-validations] Return unique set of validation errors

    • Original idea was to not take options into account in GenericValidator#==, because they often do not matter

    • It did not work out well: when you enable inferred length validation for string, but want to later explicitly declare one with Range, both should be added or explicit one won't work

    • Given possiblility of annoying duplicates in error messages because of "duplicated" validations, we have to "quick fix" it by simply returning an unique set

    [#671 state:resolved] http://github.com/datamapper/dm-...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Referenced by

Pages