MongoID 为任何异常抛出错误数量的参数。 Ruby 3.0.0 + Rails 6.1.3.1

MongoID throwing wrong number of arguments for any exception. Ruby 3.0.0 + Rails 6.1.3.1

我的筹码是

Ruby 3.0.0 Rails6.1.3.1 Mongoid 7.1.2

Mongo 在应该引发其他异常时总是抛出相同的异常:

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

例如:

我对字段进行了唯一性验证:

irb(main):010:0> Model.create!(field: 'sape')
=> #<Model _id: 606207343dcde26a1595eb48, created_at: 2021-03-29 16:58:28.006091 UTC, updated_at: 2021-03-29 16:58:28.006091 UTC, field: "sape">

irb(main):011:0> Model.create!(field: 'sape')
Traceback (most recent call last):
        1: from (irb):11:in `<main>'
ArgumentError (wrong number of arguments (given 3, expected 1..2))

find_by 相同: 如果响应找到一个,它会检索它:

irb(main):012:0> Model.find_by(field: 'sape')
=> #<Model _id: 606207343dcde26a1595eb48, created_at: 2021-03-29 16:58:28.006 UTC, updated_at: 2021-03-29 16:58:28.006 UTC, field: "sape">

但如果不存在:

irb(main):001:0> Model.find_by(field: 'sape')
Traceback (most recent call last):
        1: from (irb):1:in `<main>'
ArgumentError (wrong number of arguments (given 2, expected 0..1))

这是我的模特:

class Model
  include ActiveModel::Validations
  include Mongoid::Document
  include Mongoid::Timestamps::Created
  include Mongoid::Timestamps::Updated

  field :field, type: String, default: nil

  index({ field: 1 }, { unique: true })
end

Ruby 3 目前不受 Mongoid 支持,不应使用。

您可以看到 Rubies Mongoid 支持哪些 here

更新 mongoid gem 它将被修复

gem 'mongoid', '~> 7.3.0'