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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With