Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Remove ineffectual line from numericality validator

#5221

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.

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

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Adam Meehan
    Adam Meehan
    • Tag changed from patch validation numericality to patch, tiny, validations

    August 3rd, 2010 @ 10:44 AM

  2. Neeraj Singh
    Neeraj Singh
    • 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.

    August 4th, 2010 @ 05:26 AM

  3. Adam Meehan
    Adam Meehan

    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.

    August 4th, 2010 @ 05:40 AM

  4. Adam Meehan
    Adam Meehan

    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.

    September 10th, 2010 @ 04:51 AM

  5. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:32 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:32 PM