Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3624

read_attribute_for_validation uses getter

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Validations
    • None

      https://github.com/mongoid/mongoid/blob/8b33b62a43fb989a6a6db9beb72d98d8c84874ea/lib/mongoid/validatable.rb#L79

      The method #read_attibute_for_validation is supposed to return the value used for validation. Thus it should return the raw value and not utilize the getter from send(attr).

      It crops up as a problem in Rails https://github.com/rails/rails/blob/a3b1105ada3da64acfa3843b164b14b734456a50/activemodel/lib/active_model/validator.rb#L165 whenever you use allow_nil or allow_blank on the field and are overriding the getter.

      Since the raw value is what should be used for validation, I would argue that instead of send(attr) it should return attributes[attribute].

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            Nejuf Nejuf [X]
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: