Uploaded image for project: 'Grails'
  1. Grails
  2. GRAILS-8061

beforeValidate didn't get called in cascade validation

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.3.7
    • Fix Version/s: 2.4.5
    • Component/s: Persistence
    • Labels:
      None

      Description

      I have two classes: Parent and Child.

      class Parent {
        static hasMany = [children:Child]
      }
      
      class Child {
        static belongsTo = [parent:Parent]
      
        String name
      
        def beforeValidate() {
          name = 'hard coded in beforeValidate'
        }
      }
      

      I use the following code to create a parent instance in ParentController.

      def save = {
        def parentInstance = new Parent(params)
        parentInstance.addToChildren(new Child(name:params.name))
        if (parentInstance.save(flush: true)) {
          ...
        }
        else {
          ...
        }
      }
      

      The child instance will get created with the name passed from HTTP parameter instead of the string hard coded in the beforeValidate() method.

      1. demo.tar.gz
        200 kB
        Kenny Cheang
      2. test-beforeValidate.tar.gz
        2.06 MB
        Timo Friedl

        Issue Links

          Activity

          Hide
          Aaron Long added a comment -

          I really wish this ticket would get some priority. It makes it very hard to use beforeValidate for anything important.

          Any updates on this ticket? It has several votes but isn't even scheduled at this point. Any chance the Hibernate 4 stuff could open up new avenues?

          Show
          Aaron Long added a comment - I really wish this ticket would get some priority. It makes it very hard to use beforeValidate for anything important. Any updates on this ticket? It has several votes but isn't even scheduled at this point. Any chance the Hibernate 4 stuff could open up new avenues?
          Hide
          Jeff Scott Brown added a comment -

          We are wrapping up 2.3.2 now. I don't have time to work on this immediately myself. If this isn't resolved for 2.3.2 it probably will be for 2.3.3 and definitely for 2.4.

          Show
          Jeff Scott Brown added a comment - We are wrapping up 2.3.2 now. I don't have time to work on this immediately myself. If this isn't resolved for 2.3.2 it probably will be for 2.3.3 and definitely for 2.4.
          Hide
          Roan OSullivan added a comment -

          I'd like the echo the comment that this issue "makes it very hard to use beforeValidate for anything important."

          Show
          Roan OSullivan added a comment - I'd like the echo the comment that this issue "makes it very hard to use beforeValidate for anything important."
          Hide
          Timo Friedl added a comment -

          Having the same problem with grails 2.4.2 - added tests

          Show
          Timo Friedl added a comment - Having the same problem with grails 2.4.2 - added tests
          Hide
          Aaron Long added a comment -

          Jeff, we are coming across this time and time again lately. It tends to cause quiet failures and/or just corrupt data which is the worst kind of bug.

          I believe this ticket should be upgraded to Critical priority.

          Show
          Aaron Long added a comment - Jeff, we are coming across this time and time again lately. It tends to cause quiet failures and/or just corrupt data which is the worst kind of bug. I believe this ticket should be upgraded to Critical priority.
          Hide
          Jeff Scott Brown added a comment -

          Aaron,

          Thanks for the feedback. One of us will take a look.

          Show
          Jeff Scott Brown added a comment - Aaron, Thanks for the feedback. One of us will take a look.

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              Kenny Cheang
            • Votes:
              10 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

              • Created:
                Updated:
                Last Reviewed:

                Development