Issue Details (XML | Word | Printable)

Key: GRAILS-4472
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Graeme Rocher
Reporter: Christian Helmbold
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails

Return value of beforeUpdate closure prevents update

Created: 24/Apr/09 05:53 PM   Updated: 29/Apr/09 02:19 AM
Component/s: Persistence
Affects Version/s: 1.1
Fix Version/s: None

Time Tracking:
Not Specified

Environment: java 1.6.0_04, Linux


 Description  « Hide

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.



Graeme Rocher added a comment - 27/Apr/09 09:31 AM

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


Christian Helmbold added a comment - 29/Apr/09 02:19 AM

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