Grails

Return value of beforeUpdate closure prevents update

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.1
  • Fix Version/s: None
  • Component/s: Documentation
  • Labels:
    None
  • Environment:
    java 1.6.0_04, Linux

Description

The (implicit) return value of a beforeUpdate closure prevents updates. Maybe there is a reason for that, but then beforeInsert should be treated as well. And both should be documented!

Testcase
--------

0. create a new grails app
1. create the following domain class

class UpdateBlocker {
String password
def encode = { return false // if commented updates will work }
def beforeInsert = encode
def beforeUpdate = encode
}

2. generate-all UpdateBlocker
3. run-app
4. create a new UpdateBlocker instance with some "test" in the password field.
5. edit the instance and set password to "changed".

If you view the instance you should see "changed" in the password field, but you will see "test"! If the only line in the closure is commented, it will work as expected.

Activity

Hide
Graeme Rocher added a comment -

This is by design, returning false signfies that he operation should be aborted

Show
Graeme Rocher added a comment - This is by design, returning false signfies that he operation should be aborted
Hide
Christian Helmbold added a comment -

Ok, but then "false" should be interpreted the same way in beforInsert and beforeUpdate. And in either case it should be documented.

Show
Christian Helmbold added a comment - Ok, but then "false" should be interpreted the same way in beforInsert and beforeUpdate. And in either case it should be documented.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Last Reviewed: