Ruby 3 -不带验证的保存不再在一个表上工作



我正在将一个应用程序从Ruby 2.6.10升级到Ruby 3.0.4,并且有一个非常奇怪的情况。当我在其中一个表上执行命令record.save(validate: false)时,我得到错误消息:

ArgumentError:错误的参数数(给定1,预期0)
from/tmp/bundle/ruby/3.0.0/gems/activerecord-6.1.6/lib/active_record/suppressor。rb: 43:在"保存">

当我执行

操作时,错误仍然发生。
record = ModelName.last
record.save(validate: false)

我可以在其他表上执行相同的操作,它工作得很好。我已经禁用了模型中的所有验证和回调,但无济于事。

在Ruby 2.6.10中,同样的操作在这个表(以及所有其他表)上运行良好。

我看不出(匿名)模型有什么特别之处:

create_table "my_table", id: :integer, charset: "utf8mb4", collation: "utf8mb4_german2_ci", force: :cascade do |t|
t.integer "field_1"
t.string "field_2"
t.integer "field_3"
t.string "field_4"
t.string "field_5"
t.string "field_6"
t.string "field_7"
t.text "field_8", size: :long
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "field_9", size: :long
t.string "state", default: "raw", null: false
t.text "field_10", size: :long
t.datetime "field_11"
t.index ["state"], name: "...text replaced..."

我在Ruby 3.1.2上也有同样的问题。

有没有人对我如何调试这个有建议?有没有什么小事我可能忽略了?

在ruby 3.0.4中遇到同样的问题,原因是state_machine gem.

state_machine/integrations/active_record.rb:487: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call

当切换回ruby 2.7.6并重新运行test时,只看到警告。测试通过,但有警告。

解决,通过修复分叉的gem repo。如果有人遇到同样的情况,请随意添加到Gemfile中:

gem 'state_machine', git: 'https://github.com/Faq/state_machine.git', ref: 'd55bb212a62299837833f7b6d5f14e42bc0df8d8'

根本原因是在before_save钩子中使用的gem不再工作,需要更新。

相关内容

最新更新