Grails

Binding errors are not reported on nullable properties

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.1
  • Fix Version/s: 1.1.1
  • Component/s: Controllers
  • Labels:
    None
  • Testcase included:
    yes

Description

When binding to a domain object with a nullable property, typeMismatch errors are ignored - the property simply remains unchanged. Example is attached with a simple failing test. Removing the nullable: true from the dateOfBirth property in the domain class causes the test to pass as the binding error is detected.

Activity

Hide
Graeme Rocher added a comment -

We need to be careful with this issue, because if I recall there was another issue that asked for nullable:true to bind to null if the input was invalid. However, i think that makes sense of target type is a String and the input is a blank String like "" in which case you expect a result of null. Also if it was an Integer you would expect null to for a blank string.

So the point is the handling of blank needs to be treated differently to the handling of actual user input

Show
Graeme Rocher added a comment - We need to be careful with this issue, because if I recall there was another issue that asked for nullable:true to bind to null if the input was invalid. However, i think that makes sense of target type is a String and the input is a blank String like "" in which case you expect a result of null. Also if it was an Integer you would expect null to for a blank string. So the point is the handling of blank needs to be treated differently to the handling of actual user input
Hide
Graeme Rocher added a comment -

See GRAILS-1383 which is the issue that probably caused the regression here

Show
Graeme Rocher added a comment - See GRAILS-1383 which is the issue that probably caused the regression here
Hide
Graeme Rocher added a comment -

Actually this issue caused the regression GRAILS-1793 which describes how an empty date field can't be persisted

Show
Graeme Rocher added a comment - Actually this issue caused the regression GRAILS-1793 which describes how an empty date field can't be persisted
Hide
Peter Martin added a comment -

I just noticed this issue also I was going to post it as an issue when I saw this.

Show
Peter Martin added a comment - I just noticed this issue also I was going to post it as an issue when I saw this.
Hide
Tomislav Urban added a comment -

This is indicated as fixed, but I'm still seeing the same behavior the current version. I have a nullable integer (it's actually on a command object, not a domain class) and when I enter some invalid string "abc" it just nulls it and moves on. Worse, if I enter "abc99" it will silently strip off the non-numerical part and silently accept 99 as the value without raising an error.

Show
Tomislav Urban added a comment - This is indicated as fixed, but I'm still seeing the same behavior the current version. I have a nullable integer (it's actually on a command object, not a domain class) and when I enter some invalid string "abc" it just nulls it and moves on. Worse, if I enter "abc99" it will silently strip off the non-numerical part and silently accept 99 as the value without raising an error.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: