This project is archived and is in readonly mode.

#5221 ✓stale
Adam Meehan

Remove ineffectual line from numericality validator

Reported by Adam Meehan | July 28th, 2010 @ 12:46 AM

Removes a line in the numericality validator's validate_each method pertaining to the allow_nil option. The line checks the raw_value for nil against the allow_nil option and returns if both are true.

This line can't affect behaviour because if the raw_value is nil, then the value is also nil, and the validation would have been skipped if the allow_nil option is true.

Comments and changes to this ticket

  • Adam Meehan

    Adam Meehan August 3rd, 2010 @ 10:44 AM

    • Tag changed from patch validation numericality to patch, tiny, validations
  • Neeraj Singh

    Neeraj Singh August 4th, 2010 @ 05:26 AM

    • Importance changed from “” to “Low”

    I agree that things will work fine even without the lines you removed. However I would keep those two lines for two reasons

    • performance will be better since it will exit early.

    • it is self documenting. It is easier to read and see what is happening.

  • Adam Meehan

    Adam Meehan August 4th, 2010 @ 05:40 AM

    I disagree on the second point. The validates_each method is never called if the raw_value is nil and option :allow_nil is true.

    The allow_nil and allow_blank checks are done in the validate method . Leaving this line is suggests otherwise to the casual reader.

  • Adam Meehan

    Adam Meehan September 10th, 2010 @ 04:51 AM

    Performance will not be better with the lines left in. It's a completely unnecessary check.

    If you look into the validate method you will see that a validator with the :allow_nil => true and nil raw value will never reach this code.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:32 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:32 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages