Grails
  1. Grails
  2. GRAILS-8580

Command Object default nullable constraint not working

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 2.0 final
    • Fix Version/s: None
    • Component/s: Controllers
    • Labels:
    • Environment:
      Windows XP, JDK1.6
    • Testcase included:
      yes

      Description

      Upgraded a 1.3.6 project to 2.0 final. Test cases failed because of failed validation.
      Zeroed in on the problem by creating a sample application.

      Steps to reproduce,
      Define any static constraint (other than nullable, example display:false) for a field in a Command Object
      Send in a request to the action without the field
      validation fails. Reason the field value cannot be null.

      Expected:
      Validation shouldn't fail for nullability, as default value for nullable is 'true' according to the documentation. Older versions of Grails have the same behaviour. This works fine in Grails 1.3.6.

      Example controller:

      class BookController {

      def index = {TestCommand cmd ->
      if (cmd.hasErrors()) {
      println "has Errors"
      cmd.errors.each

      { println it }

      render 'Error'
      } else

      { println "Success" render 'Hello World' }

      }
      }

      class TestCommand {
      Integer i;
      String name

      static constraints =

      { name(display: true) }

      }

      Attached a sample application, with failing unit test case

        Issue Links

          Activity

          Hide
          Jeff Scott Brown added a comment -

          See http://jira.grails.org/browse/GRAILS-2402.

          Does the documentation say that nullable defaults to true?

          Show
          Jeff Scott Brown added a comment - See http://jira.grails.org/browse/GRAILS-2402 . Does the documentation say that nullable defaults to true?
          Hide
          IraByte added a comment -

          Yes, it says so,

          http://www.grails.org/doc/2.0.x/guide/single.html#constraints
          Look at the warning message,which states the following
          "By default, all domain class properties are not nullable (i.e. they have an implicit nullable: false constraint). The same is not true for command object properties, which are nullable by default"

          If this behaviour was changed according to the related bug, then it would break backward compatibility. It would be great if there is a way to flip the default behaviour only for command objects and not domain.
          Is it possible?

          Moreover, it would be nice if this change in behaviour be documented in upgrade section.

          Show
          IraByte added a comment - Yes, it says so, http://www.grails.org/doc/2.0.x/guide/single.html#constraints Look at the warning message,which states the following "By default, all domain class properties are not nullable (i.e. they have an implicit nullable: false constraint). The same is not true for command object properties, which are nullable by default" If this behaviour was changed according to the related bug, then it would break backward compatibility. It would be great if there is a way to flip the default behaviour only for command objects and not domain. Is it possible? Moreover, it would be nice if this change in behaviour be documented in upgrade section.
          Hide
          Jeff Scott Brown added a comment -

          The behavior is correct. The docs are out of date. The docs have been updated. The next time the user guide is published the docs will clarify this.

          Thanks for the help.

          Show
          Jeff Scott Brown added a comment - The behavior is correct. The docs are out of date. The docs have been updated. The next time the user guide is published the docs will clarify this. Thanks for the help.
          Hide
          IraByte added a comment -

          Is it possible, to make nullable:true for all command objects through configuration?
          We have lots of test cases affected by this change.

          Show
          IraByte added a comment - Is it possible, to make nullable:true for all command objects through configuration? We have lots of test cases affected by this change.
          Hide
          Jeff Scott Brown added a comment -

          No, I don't think so.

          Show
          Jeff Scott Brown added a comment - No, I don't think so.

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              IraByte
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development