# 分类专家插件在合并用户时崩溃

**URL:** <https://meta.discourse.org/t/category-experts-plugin-crashes-on-merging-users/399785>\
**Category:** Bug\
**Tags:** category-experts, fixed\
**Created:** [2026年四月2日 11:09 UTC](https://meta.discourse.org/t/category-experts-plugin-crashes-on-merging-users/399785 "2026-04-02T11:09:08Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2026年四月2日 11:09 UTC](https://meta.discourse.org/t/category-experts-plugin-crashes-on-merging-users/399785/1 "2026-04-02T11:09:08Z")

</div>

通过命令行合并两个用户时，合并操作因“分类专家”插件（discourse-category-experts）崩溃而失败。在合并前禁用该插件后，问题得以解决。

```plaintext
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Body can't be blank, Body seems unclear, is it a complete sentence? (ActiveRecord::RecordInvalid)
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/validations.rb:87:in `raise_validation_error'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/validations.rb:54:in `save!'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/transactions.rb:365:in `block in save!'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/transactions.rb:417:in `block (2 levels) in with_transaction_returning_status'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/connection_adapters/abstract/transaction.rb:626:in `block in within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activesupport-8.0.4/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/connection_adapters/abstract/transaction.rb:623:in `within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/connection_adapters/abstract/database_statements.rb:367:in `within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/connection_adapters/abstract/database_statements.rb:359:in `transaction'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/transactions.rb:413:in `block in with_transaction_returning_status'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/connection_handling.rb:312:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/transactions.rb:409:in `with_transaction_returning_status'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/transactions.rb:365:in `save!'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/activerecord-8.0.4/lib/active_record/suppressor.rb:56:in `save!'
/var/www/discourse/plugins/discourse-category-experts/plugin.rb:351:in `block (2 levels) in activate!'
/var/www/discourse/lib/plugin/instance.rb:637:in `block in on'
/var/www/discourse/lib/discourse_event.rb:12:in `block in trigger'
/var/www/discourse/lib/discourse_event.rb:12:in `trigger'
/var/www/discourse/app/models/post.rb:878:in `set_owner'
/var/www/discourse/app/services/post_owner_changer.rb:30:in `bl

```

[代码](https://github.com/discourse/discourse-category-experts/blob/main/plugin.rb#L351)：

```rb
  on(:post_owner_changed) do |post, old_owner, new_owner|
    previously_approved = !post.custom_fields[CategoryExperts::POST_PENDING_EXPERT_APPROVAL]
    post.custom_fields.delete(CategoryExperts::POST_APPROVED_GROUP_NAME)
    post.custom_fields.delete(CategoryExperts::POST_PENDING_EXPERT_APPROVAL)
    post.save!
    CategoryExperts::PostHandler.new(post: post, user: new_owner).process_new_post(
      previously_approved: previously_approved,
    )
  end

```

由于该处唯一的修改操作是针对 `post.custom_fields`，我认为调用 `post.save!` 是多余的，使用 `post.save_custom_fields` 就足够了。

---

_[View the full topic](https://meta.discourse.org/t/category-experts-plugin-crashes-on-merging-users/399785)._
