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

Validation Errors on Ruby 3

    XMLWordPrintable

    Details

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

      Description

      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={}>

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: