Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0.1
-
Fix Version/s: 1.0.2
-
Component/s: None
-
Labels:None
Description
Per discussions on the mailing list, add the capability to veto a nullable / blank constraint check in order to allow custom validation to fire.
Link to thread (contains syntax suggestions): http://www.nabble.com/Nullable-and-vetoing-to15645476.html
Original post by Peter Ledbrook Feb 22, 2008
Hi,
Has anyone else noticed that 'nullable: true' vetoes all the other
constraints even if it passes? So for example:
class Book {
String title
String isbn
static constraints = {
title(nullable: false, blank: false)
isbn(nullable: true, validator: { val -> println ">>> $val" })
}
}
If 'isbn' is null, then the custom validator is not executed. This
can't be right, surely? The same applies to the "blank: true"
constraint if the field value is blank.
I would change this myself, but the unit test actually expects this
behaviour so I want to check why first.
Thanks,
Peter
Attachments
-
$i18n.getText("admin.common.words.hide")
- veto-bug-report-19032008.zip
- 19/Mar/08 2:58 PM
- 32 kB
- Mike Hugo
-
- grails-app/conf/BootStrap.groovy 0.1 kB
- grails-app/conf/Config.groovy 3 kB
- grails-app/conf/DataSource.groovy 0.6 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/domain/Book.groovy 0.5 kB
- grails-app/i18n/messages.properties 2 kB
- grails-app/i18n/messages_de.properties 3 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 2 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_th.properties 5 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/error.gsp 1 kB
- grails-app/views/layouts/main.gsp 0.7 kB
- test/integration/BookTests.groovy 2 kB
- test/reports/TEST-BookTests-err.txt 0.2 kB
- test/reports/TEST-BookTests-out.txt 0.2 kB
- test/reports/TEST-BookTests.xml 41 kB
- test/reports/TESTS-TestSuites.xml 41 kB
- test/reports/html/0_BookTests-err.txt 0.2 kB
- test/reports/html/0_BookTests-out.txt 0.2 kB
- test/reports/html/0_BookTests.html 46 kB
- test/reports/html/all-tests.html 44 kB
- test/reports/html/allclasses-frame.html 0.5 kB
- test/reports/html/alltests-errors.html 0.8 kB
- test/reports/html/alltests-fails.html 43 kB
$i18n.getText("admin.common.words.show")- veto-bug-report-19032008.zip
- 19/Mar/08 2:58 PM
- 32 kB
- Mike Hugo
Issue Links
| This issue duplicates: | ||||
| GRAILS-2594 | contraint logic is incorrect |
|
|
|
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Attaching sample application that demonstrates the problem.
Run grails test-app and there are two tests that will fail (and a third that passes). All three should pass...after this ticket is resolved ![]()
The basic premise of the example is that a Book has a boolean flag (online). If online == true, then the String property onlineFormatDescription is required...
I haven't implemented the ability to control veto'ing but i have changed it so that veto'ing only occurs if validation on nullable and blank failed. This was the premise of the original discussion here http://www.nabble.com/Constraints-behavior-on-blank-strings-td12581281.html#a12581281 and in that discussion this was how we agreed it should behave.
Somehow in the process of implementing it was changed so that veto'ing occured even if nullable and blank passed, which is the real bug here. With these changes your unit tests pass and I have added them to the grails build so that they will always pass in future. If we REALLY need veto control then we can consider adding it for 1.1 or beyond.
Graeme, it was me who implemented this feature and the reason was: if nullable and blank constraint won't veto on passed validation, then we must ensure that all other constraints accept null and blank string as valid values and don't generate additional errors.
Consider the example:
aField(blank:true,url:true)
For a blank string in this field one would expect only one error "Field cannot be blank" and not the "Field must be a valid url" (and there were several posts in ML and JIRA issues about this expected behavior). Since we're AND-ing constraints and cannot OR them we could achieve this behavior by ensuring that all constraints (except nullable and blank) pass for nulls and blank strings (and all custom user-defined constraints must implement this also). You implemented this recently for email constraint if I recall correctly.
In this case we don't need any veto'ing completely. It has no reason to exist since all constraints must accept nulls and blank strings and there's no reason to stop validation if null or blank string was catched by respective constraint. So, at the end we are near the beginning hitting the problem with blank constraint which was described in my first message in the thread you've referenced: http://www.nabble.com/Constraints-behavior-on-blank-strings-td12581281.html#a12581281.
Am I missing something obvious here?
aField(blank:true,url:true)
I just ran into this situation. I upgraded a grail 0.6 app to 1.0.1, and this didn't work. That is, I had nullable:true and a custom validator. The validator is never executed anymore. Because it didn't work anymore, my first reaction is that it's a bug... but now I don't think it's a bug. I was able to easily change the code around any way (for the better). Before it had nullable true and then the validator set the value based on other attributes... but that's kind of a hack that isn't needed in my situation after all.
Hi Sergey, I understand the problem its trying to address, but I think the only sensible solution is to do what I did with email and make other constraints ignore blank and null values. It is very surprising for a user that applying blank or nullable results on vetoing the remaining constraints and as I said I don't think it was the behaviour that was agreed on the above thread
Ok, I agree, but in this case we could completely remove all "vetoing" logic since it becomes useless. All other constraints will pass for nulls and blank strings hence there is no need to veto. And again: in this case blank string will be accepted for property with constraints aProperty(email:true) since blank constraint is not applied by default as nullable. This could be confusing for users I think so at least we should describe this behavior in User Guide properly.
What was the actual resolution to this issue? There was a lot of discussion as to possibilities but how was the issue solved?
This is the same issue as
GRAILS-2594contraint logic incorrect (sorry about the typo) which has already been moved to 1.1 release.http://jira.codehaus.org/browse/GRAILS-2594
GRAILS-2594contraint logic incorrect (sorry about the typo) which has already been moved to 1.1 release. http://jira.codehaus.org/browse/GRAILS-2594