#764 ✓resolved
Jamie Macey

:nullable => false, :default => "" fails nullable auto-validation

Reported by Jamie Macey | January 13th, 2009 @ 11:37 AM | in 0.10.0

I would like to keep my prop definitions the same as my migrations, but if I have a Page model with

property :meta_kw, String, :nullable => false, :default => ""

When I call Page.new.save, it says there's an error that meta_kw should not be null, even though the database will provide one, and I expect datamapper to provide one.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 21st, 2009 @ 01:25 AM

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

    This is a problem with how dm-validations works with dm-core.

    dm-core defers setting the default values until either:

    1. The attribute accessor is used for the first time
    2. The resource is being saved and the attribute is not loaded (the ivar is not defined)

    This is done for performance reasons. If we initialized the object with every default value set, only to overwrite them immediately anyway with the passed-in values, it would've been a waste of resources.

    Anyway, when dm-validations executes it happens prior to step 2 above, and would see the attribute as being nil.

    What should probably happen is dm-validations should be updated so that instead of just checking whether something is nil (and raising a validation error) it should call a method that checks if it is nil and it has no default value before raising any errors.

  • Michael Klishin (antares)

    Michael Klishin (antares) March 25th, 2009 @ 03:24 PM

    • Milestone set to 0.10.0
    • State changed from “confirmed” to “resolved”

    Should be fixed now, in next branch (future 0.10) :allow_nil for validations (which :nullable => false uses) checks for blank?, not nil?, and thus empty string would be considered invalid

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 »