Grails

Inherited Constraints not validated

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-RC4
  • Fix Version/s: 1.0-RC4
  • Component/s: Persistence
  • Labels:
    None
  • Testcase included:
    yes

Description

The constraints added in a subclass are are ignored in save() and validate()

class Parent {
   static constraints = {
        prop1(nullable: false, blank: false)
   }

   String prop1
}
class Child extends Parent {
   static constraints = {
      other(nullable: true)
   }

   Other other
}
class Other {
   String prop
}
void testSubClassConstraints() {
        def second = new Second()
        second.prop1 = "Property 1"

        def valid = second.validate()
        def errors = second.errors

        // both will fail
        assert valid 
        assert errors.errorCount == 0
    }

The Problem is, that in ConstraintsEvaluatingDynamicProperty.java, line 86, the constraints-Closure is received through a call to GrailsClassUtils.getStaticPropertyValue(..), which again tries to get the getter for the constraint-property, invokes it and returns the value.

However, the getter-Method whicht should be Child.getConstraints() is never found - instead Parent.getConstraints() is returned which results in a duplicate instantiation of the validators defined in Parent.constraints. Child.contraints ist never processed.

The attached zip-File contains a Grails-Bugreport containing the same Code as above.

Activity

Hide
Christian Laakmann added a comment -

Hmm.. obviously the test-method would not work as above - rename Parent to First and Child to second and you're done

Show
Christian Laakmann added a comment - Hmm.. obviously the test-method would not work as above - rename Parent to First and Child to second and you're done
Hide
Graeme Rocher added a comment -
Show
Graeme Rocher added a comment - Caused by http://jira.codehaus.org/browse/GROOVY-2490

People

Vote (3)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: