Kathy Stone
Kathy Stone

Reputation: 55

Purpose of blank constraint in Grails 2.4?

I would like to start a discussion on the purpose of the blank constraint now that data binding has changed in Grails 2.4 to convert incoming empty(blank) strings from request params to null. Would it be useful to catch validation errors from data not introduced via a web request? We are considering removing many of our application's blank constraints. We do have information also coming into the app from file uploads and web services. Thanks in advance.

Upvotes: 0

Views: 86

Answers (2)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27200

If your rule is that you don't want to allow blank values then I think it is perfectly reasonable and probably a good idea to express that as a constraint. The fact that the data binder converts blanks to null by default will help make sure blank values are not assigned when the data binder is used, but that shouldn't replace expressing that blank values are not allowed. If you leave the constraint off and there is ever a mistake in the app (or the framework, or a plugin, etc...) that causes your rule to be violated, you won't know about it.

Upvotes: 0

Dónal
Dónal

Reputation: 187499

You're correct that the blank constraint is largely redundant since Grails 2.4 when the data is bound from a web request). However it's still necessary to validate data from other sources, e.g. a daily Quartz job that downloads data from a web service and saves it to the database. Because there's no databinding involved, blanks would not be converted to null, so the constraint is still required.

Upvotes: 1

Related Questions