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

Validation Errors on Ruby 3

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.3.1, 7.2.4, 7.1.9
    • Affects Version/s: 7.3.0
    • Component/s: Validations
    • None
    • Environment:
      Ruby 3.0.0

      I am utilizing the master branch for the Rails 6.1 support and I've come across an issue when an ActiveModel validation attempts to add an error:

      wrong number of arguments (given 3, expected 1..2)

       On line 45 of mongoid/validatable/presence.rb (but it affects all validatables) it attempts to add the error to the document as such:

      document.errors.add(attribute, :blank, options) if not_present?(value)

      For me, attribute is :host and options is just an empty hash. It looks like Rails 6.1 now splats this last argument after this change:

      https://github.com/rails/rails/commit/d9011e39357300fe78720227af4c13b4bc4ac4dd#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31L308

      I think for each of these, we'll need to splat them ourselves first to avoid this error.

      >> document.errors.add(:host, :blank, {})
      ArgumentError: wrong number of arguments (given 3, expected 1..2)
      	from (eval):1:in `validate_each'
      >> document.errors.add(:host, :blank, **{})
      => #<ActiveModel::Error attribute=host, type=blank, options={}>

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            mauricio@moonbase.tech Mauricio Gomes
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: