Bug 40033 - The background jobs page calls GetPlugins incorrectly, resulting in a 500 error
Summary: The background jobs page calls GetPlugins incorrectly, resulting in a 500 error
Status: Pushed to oldstable
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low major
Assignee: HKS3 Tadeusz Sośnierz
QA Contact: David Cook
URL:
Keywords: rel_25_05_candidate
Depends on: 39772
Blocks:
  Show dependency treegraph
 
Reported: 2025-05-30 11:13 UTC by HKS3 Tadeusz Sośnierz
Modified: 2025-06-19 09:02 UTC (History)
3 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes the background jobs page (Koha administration > Jobs > Manage jobs) so that it doesn't generate a 500 error when a plugin does not have a background task (it currently calls GetPlugins incorrectly).
Version(s) released in:
25.11.00,25.05.01,24.11.06
Circulation function:


Attachments
Bug 40033: Call GetPlugins correctly in background_jobs.pl (1003 bytes, patch)
2025-05-30 11:15 UTC, HKS3 Tadeusz Sośnierz
Details | Diff | Splinter Review
Bug 40033: Call GetPlugins correctly in background_jobs.pl (1.03 KB, patch)
2025-05-31 21:43 UTC, David Nind
Details | Diff | Splinter Review
Bug 40033: Call GetPlugins correctly in background_jobs.pl (1.08 KB, patch)
2025-06-02 01:09 UTC, David Cook
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description HKS3 Tadeusz Sośnierz 2025-05-30 11:13:18 UTC
In the aforementioned script, GetPlugins is used as so:

```
my @plugins = Koha::Plugins::GetPlugins(
    {
        method => 'background_tasks',
    }
);
my @plugin_job_types;
for my $plugin (@plugins) {
    my $tasks = $plugin->background_tasks;

```

This currently results in a 500 when it tries to call background_tasks on a plugin that doesn't have it. The reason for this is an incorrect method call to GetPlugins – since there is no invocant, the $params get intepreted as $self (with $params ending up undefined), and so the method filtering doesn't work – which is why we end up calling background_tasks on plugins we did not want to.

In the rest of Koha it's universally used as `Koha::Plugins->new()->GetPlugins()`, so it makes sense to follow that trend here. At the same time, I wonder if a more strict linting rules (or a safer API) could've prevented it from happening in the first place.
Comment 1 HKS3 Tadeusz Sośnierz 2025-05-30 11:15:55 UTC
Created attachment 182856 [details] [review]
Bug 40033: Call GetPlugins correctly in background_jobs.pl

Test plan:

1. Install a plugin that does not have any background_tasks, e.g. https://github.com/HKS3/HKS3GeoSearch/releases/tag/v0.12
2. Navigate to http://localhost:8081/cgi-bin/koha/admin/background_jobs.pl, observe a 500
3. Apply patch
4. Observe no 500
Comment 2 David Nind 2025-05-31 21:43:05 UTC
Created attachment 182886 [details] [review]
Bug 40033: Call GetPlugins correctly in background_jobs.pl

Test plan:

1. Install a plugin that does not have any background_tasks, e.g. https://github.com/HKS3/HKS3GeoSearch/releases/tag/v0.12
2. Navigate to http://localhost:8081/cgi-bin/koha/admin/background_jobs.pl, observe a 500
3. Apply patch
4. Observe no 500

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2025-05-31 21:47:58 UTC
Added assignee, changed to a normal bug (fixes something that is broken/not working as it should), changed the title.
Comment 4 David Cook 2025-06-02 00:34:30 UTC
Upgrading to major since it's quite a significant failure.
Comment 5 David Cook 2025-06-02 01:09:10 UTC
Created attachment 182894 [details] [review]
Bug 40033: Call GetPlugins correctly in background_jobs.pl

Test plan:

1. Install a plugin that does not have any background_tasks, e.g. https://github.com/HKS3/HKS3GeoSearch/releases/tag/v0.12
2. Navigate to http://localhost:8081/cgi-bin/koha/admin/background_jobs.pl, observe a 500
3. Apply patch
4. Observe no 500

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Comment 6 Lucas Gass (lukeg) 2025-06-02 21:28:01 UTC
Nice work everyone!

Pushed to main for 25.11
Comment 7 David Cook 2025-06-04 03:24:51 UTC
Not sure who is supposed to add "rel_25_05_candidate" here. I'm adding it here, but someone let me know if that's wrong...

Note this only needs to be backported to 25.05 (unless 39772 gets backported too I guess...)
Comment 8 Fridolin Somers 2025-06-19 07:46:45 UTC
I see in 25.05.x
Comment 9 Fridolin Somers 2025-06-19 07:48:50 UTC
Bug 39772 backported plus this one

Pushed to 24.11.x for 24.11.06
Comment 10 Paul Derscheid 2025-06-19 09:02:07 UTC
Nice work everyone!

Pushed to 25.05.x for 25.05.03