Grails beforeUpdate filter fails without log.info

Ok, I know I’m missing something here, but I don’t know what it is. At any rate, trial and error has taught me that my beforeUpdate (and probably beforeInsert too, just haven’t tested that yet) prevent the update (or insert?) from completing, unless I add some extra code to “jiggle” it. Sounds crazy, right? But check it out:

class MyDomain {
    String name
    Boolean active = true
    Date dateCreated
    Date lastUpdated
    private deactive() {
       if (name == null || name?.length() == 0) {
         active= false
       }
    }
    def beforeUpdate() {
       deactive()
       log.info "This must be a bug, right?"
    }
}

Without the log.info line, the update fails to execute at all (and no error is thrown); with the log.info, it runs fine. The deactive function works, in debug I see that all values are set correctly (note this domain is simplified and genericified for illustration), but the update request is never sent (per watching SQL Profiler (this is MS SQL).

Obviously the log.info is not important – I haven’t tried all sorts of different things, but probably a lot of different things could be done there – but I shouldn’t have to do anything besides the function that I am actually trying to run. Sigh…

No Comments

Leave a Reply

Your email is never shared.Required fields are marked *