# Discourse 自动化插件因“内部服务器错误”而失效

**URL:** <https://meta.discourse.org/t/discourse-automation-plugin-failing-with-an-internal-server-error/361207>\
**Category:** Bug\
**Tags:** automation\
**Created:** [2025年四月10日 08:06 UTC](https://meta.discourse.org/t/discourse-automation-plugin-failing-with-an-internal-server-error/361207 "2025-04-10T08:06:36Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![gassim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gassim/32/220910_2.png) [@gassim](https://meta.discourse.org/u/gassim)\
**Post date:** [2025年四月10日 08:06 UTC](https://meta.discourse.org/t/discourse-automation-plugin-failing-with-an-internal-server-error/361207/1 "2025-04-10T08:06:36Z")

</div>

在最新的更新之前，有一个使用自动化插件的自动化，其功能如下（经过测试，无需任何更改即可成功运行）：

- 脚本：发送私信
- 时间：“用户被添加到群组时”
- 跟踪的群组：“一个需要群组所有者先‘批准请求’的群组”
- 脚本选项：一条私信（经过测试，成功运行）。

目前，在版本：`3.5.0.beta3-dev(231e9ca99a)` 中，在尝试批准用户时会显示“内部服务器错误”。

以下是出现的错误：

```plaintext
PG::NotNullViolation (ERROR: null value in column "total_time" of relation "discourse_automation_stats" violates not-null constraint
DETAIL: Failing row contains (18, 8, 2025-04-10, 2025-04-10 07:34:42.740189, null, null, null, null, 1).
)
lib/mini_sql_multisite_connection.rb:109:in `run'
lib/plugin/instance.rb:609:in `block in on'
lib/discourse_event.rb:12:in `block in trigger'
lib/discourse_event.rb:12:in `trigger'
app/models/group.rb:869:in `trigger_user_added_event'
app/models/group.rb:838:in `add'
app/controllers/groups_controller.rb:502:in `block in handle_membership_request'
app/controllers/groups_controller.rb:500:in `handle_membership_request'
app/controllers/application_controller.rb:427:in `block in with_resolved_locale'
app/controllers/application_controller.rb:427:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:35:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:410:in `call'
lib/middleware/csp_script_nonce_injector.rb:12:in `call'
config/initializers/008-rack-cors.rb:26:in `call'
lib/middleware/default_headers.rb:13:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/processing_request.rb:12:in `call'
lib/middleware/request_tracker.rb:385:in `call'

```

我怀疑这与此处提到的 discourse\_automation\_stats 表的新更改有关：

[quote] @sam

> <https://github.com/discourse/discourse/pull/31921>
>
> introduces comprehensive statistics tracking for the Discourse Automation plugin…, allowing users to monitor the performance and execution patterns of their automations:
> 
> \- Add \`discourse\_automation\_stats\` table to track execution metrics including run counts, execution times, and performance data
> \- Create a new \`Stat\` model to handle tracking and retrieving automation statistics
> \- Update the admin UI to display automation stats (runs today/this week/month and last run time)
> \- Modernize the automation list interface using Glimmer components
> \- Replace the older enable/disable icon with a toggle switch for better UX
> \- Add schema annotations to existing models for better code documentation
> \- Include extensive test coverage for the new statistics functionality
> 
> This helps administrators understand how their automations are performing and identify potential bottlenecks or optimization opportunities.

[/quote]

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/4/6/946c20bb730b05df374d9373edd3970b8d4178de.png)

谢谢！

---

_[View the full topic](https://meta.discourse.org/t/discourse-automation-plugin-failing-with-an-internal-server-error/361207)._
