Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails Validation Not Working After Upgrade

I am in the process of upgrading my Grails 1.3.7 app to 2.0.3 and I have fixed most issues. However, I have code that used to work that creates a user and saves them to the database. The code should NOT pass validation as I am reusing a username that is already taken and there is a unique constraint on username. .validate() returns true, but then the code actually bombs when user.save() is called with a MySql unique constraint error.

Should throw an error:

def submitSignup = {
        def user = new User(params)

        user.validate()
        if (!user.hasErrors()) {
            ...
            // This line bombs with the MySql unique constraint I would have expected .validate() to get
            user.save()
        }
}

In User.groovy:

static constraints = {
    username(blank: false, unique: true);
    ...
}

Any ideas?

EDIT: I am also upgrading to the Spring Security plugin from Acegi. I don't think this would be relevant, but I figured I would mention it.

I put up a sample that suffers from the problem at: https://github.com/skazzaks/Grails-Unique-Test This makes it definitely look like a bug.

like image 788
skaz Avatar asked May 18 '12 12:05

skaz


1 Answers

I was experiencing a similar weird validation issue a couple of days ago while upgrading from 1.3.7 to 2.0.3.

What did the trick for me was a manual clearing of my target dir. Apparently recompiling of all the classes put the application back on track.

Don't know if it will work in your case though, but might be worth a try.

like image 53
John Doppelmann Avatar answered Oct 05 '22 01:10

John Doppelmann