framework icon indicating copy to clipboard operation
framework copied to clipboard

[2.x] Extension Manager: queued tasks fail on PostgreSQL (output NOT NULL, command varchar(50))

Open s-asoft opened this issue 1 month ago • 1 comments

Current Behavior

With the queue enabled ('queue' => ['driver' => 'database']) and "queue jobs" turned on in the Extension Manager, two schema problems in extension_manager_tasks break tasks on PostgreSQL. MySQL in non-strict mode silently stores '' and truncates, so they go unnoticed there.

1. Every queued task fails to be created. Task::build() saves a pending task without setting output, but the column is mediumText('output') with no ->nullable(). The admin UI shows "Database query failed. This may be caused by an incompatibility between an extension and your database driver." and the log has:

SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "output" of relation "extension_manager_tasks" violates not-null constraint
DETAIL:  Failing row contains (1, pending, extension_update, null, fof/links, null, 2026-10-07 01:02:45, null, null, null, null).

2. The Global Update is recorded as failed after Composer has finished. command is string('command', 50), but the global update command is 56 characters (update --prefer-dist --no-dev -a --with-all-dependencies). Composer completes, then Task::end() cannot save the row:

SQLSTATE[22001]: String data, right truncated: 7 ERROR:  value too long for type character varying(50)
(SQL: update "extension_manager_tasks" set "status" = failure, "command" = update --prefer-dist --no-dev -a --with-all-dependencies, ...)

The job then stops, so the steps after the update never run: a pending migration from an updated extension stayed unapplied until I ran php flarum migrate by hand.

Steps to Reproduce

  1. Install Flarum 2.x on PostgreSQL and enable the Extension Manager.
  2. Set 'queue' => ['driver' => 'database'] in config.php and enable queued jobs in the Extension Manager settings.
  3. Click "Update" on any extension: the task is never created and the alert above appears (bug 1).
  4. With output made nullable, click "Run Global Update": Composer finishes, but the task ends as failed with the varchar(50) error (bug 2).

Expected Behavior

Tasks are created, and the global update is recorded as successful, on PostgreSQL (and SQLite or strict MySQL) just as on non-strict MySQL.

Environment

  • Flarum version: core v2.0.0-rc.8, flarum/extension-manager v2.0.0-rc.5 (the same code is unchanged on 2.x)
  • Website URL: private test site
  • Webserver: Caddy with PHP-FPM
  • Hosting environment: VPS
  • PHP version: 8.5.4
  • Database: PostgreSQL 18.6
  • Browser: not relevant (server side)

Possible Solution

Set output to an empty string when building a task, and widen command to text (a major update lists every extension, so 255 may also be too short). The patch below applies cleanly to 2.x. I applied the equivalent schema change on our install, and both kinds of task now save.

diff --git a/extensions/package-manager/src/Task/Task.php b/extensions/package-manager/src/Task/Task.php
--- a/extensions/package-manager/src/Task/Task.php
+++ b/extensions/package-manager/src/Task/Task.php
@@ -68,6 +68,8 @@ class Task extends AbstractModel
         $task->operation = $operation;
         $task->package = $package;
         $task->status = static::PENDING;
+        // The output column is NOT NULL; PostgreSQL and SQLite reject a pending task without it.
+        $task->output = '';
         $task->created_at = Carbon::now();
 
         $task->save();
diff --git a/extensions/package-manager/migrations/2026_10_07_000000_change_command_column_to_text_in_extension_manager_tasks_table.php b/extensions/package-manager/migrations/2026_10_07_000000_change_command_column_to_text_in_extension_manager_tasks_table.php
new file mode 100644
--- /dev/null
+++ b/extensions/package-manager/migrations/2026_10_07_000000_change_command_column_to_text_in_extension_manager_tasks_table.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of Flarum.
+ *
+ * For detailed copyright and license information, please view the
+ * LICENSE file that was distributed with this source code.
+ */
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Schema\Builder;
+
+return [
+    'up' => function (Builder $schema) {
+        // Composer commands such as the global update are longer than 50 characters.
+        // MySQL in non-strict mode truncates them; PostgreSQL rejects the row.
+        $schema->table('extension_manager_tasks', function (Blueprint $table) {
+            $table->text('command')->nullable()->change();
+        });
+    },
+    'down' => function (Builder $schema) {
+        $schema->table('extension_manager_tasks', function (Blueprint $table) {
+            $table->string('command', 50)->nullable()->change();
+        });
+    }
+];

Additional Context

The Extension Manager's Dispatcher silently skips a new request while another task is pending or running, so after bug 1 the UI gives no further feedback on retries.

s-asoft avatar Oct 07 '26 01:10 s-asoft

In Flarum 2.1, the Extension Manager is replaced by an entirely new implementation (flarum/framework#5257), so the code this issue is about no longer exists. I'm closing it as stale. If you still see this problem with the new Extension Manager, please open a new issue on flarum/framework. Thanks for reporting it!

imorland avatar Oct 23 '26 11:10 imorland