Grails

contraint logic is incorrect

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.0.2
  • Component/s: Persistence
  • Labels:
    None
  • Environment:
    N/A

Description

Constraint logic is incorrect. All constraints should evaluate to true before writing object to database. This is especially problematic with nullable.

This constraint will evauate to true if the user leaves the field blank:

static constraints = {
field (validator: {return false}, nullable:true)
}

A real world example would look like this:

class Book {
Boolean published
String isbn
plus several more fields that become required if book is published

static constraints = {
isbn (validator: {val,obj -> if (obj.published && !val)) return false}, nullable:true)
}
}

Issue Links

Activity

Hide
Graeme Rocher added a comment -

I'm not sure what the issue is exactly, please elaborate on the what the problem is and attach an example app

Show
Graeme Rocher added a comment - I'm not sure what the issue is exactly, please elaborate on the what the problem is and attach an example app
Hide
Sergey Nebolsin added a comment -

This is by design now (but maybe we should change this) and here is some recent discussion on this topic: http://www.nabble.com/Nullable-and-vetoing-td15645476.html#a15645476

Show
Sergey Nebolsin added a comment - This is by design now (but maybe we should change this) and here is some recent discussion on this topic: http://www.nabble.com/Nullable-and-vetoing-td15645476.html#a15645476
Hide
Matt Lentzner added a comment -

IMO, the custom validator should run first. That is the "correct" behavior. Being able to make the nullable constraint conditional is very important.

Having slept on this, my take has changed a bit. It is not a bug, but an improvement. It is also a breaking change as already written custom validators will have to handle potential nulls. So maybe it is more appropriate for the 1.1 release (but please don't put it off any longer than that!).

Show
Matt Lentzner added a comment - IMO, the custom validator should run first. That is the "correct" behavior. Being able to make the nullable constraint conditional is very important. Having slept on this, my take has changed a bit. It is not a bug, but an improvement. It is also a breaking change as already written custom validators will have to handle potential nulls. So maybe it is more appropriate for the 1.1 release (but please don't put it off any longer than that!).
Hide
Graeme Rocher added a comment -

Will be fixed when we introduced optional veto'ing

Show
Graeme Rocher added a comment - Will be fixed when we introduced optional veto'ing
Hide
Graeme Rocher added a comment -

Fixed, see info in GRAILS-2656

Show
Graeme Rocher added a comment - Fixed, see info in GRAILS-2656
Hide
Graeme Rocher added a comment -

Bulk closing bunch of resolved issues

Show
Graeme Rocher added a comment - Bulk closing bunch of resolved issues

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: