Notice: Undefined index: sets in /core/includes/form.inc line 898

Created on 19 August 2020, over 4 years ago
Updated 6 February 2023, about 2 years ago

Problem/Motivation

It's possible to run batch even if there are no tasks to be done. Which can cause Notice: Undefined index: sets in /core/includes/form.inc line 898 notifications any time and can break Behat tests.

Steps to reproduce

Call from code the execute the batch without adding any batch tasks. A good starting point is how Behat calls the batch process:

    $batch =& batch_get();
    $batch['progressive'] = FALSE;
    batch_process();

Proposed resolution

The problem comes from the /core/includes/form.inc:874 line, where we can see the `if (isset($batch)) {` condition. This will evaluate always to true because the `batch_get()` will return by default an empty array or something within an array structure. If my assumption correct, the batch process only run tasks if there is 'sets' key inside the array, otherwise, it doesn't do anything, therefore instead of the current condition it would be a better solution to check if there is any task(s) to run `if (isset($batch['sets'])) {`.

Remaining tasks

Implementation if it's correct.

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

none

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
BatchΒ  β†’

Last updated 23 days ago

Created by

πŸ‡§πŸ‡ͺBelgium golddragon007

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Triggering for 10.1
    Removing tests tag

  • Status changed to RTBC about 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Tested following the IS by placing

        $batch =& batch_get();
        $batch['progressive'] = FALSE;
        batch_process();
    

    In a preprocess hook.

    Without the fix I get a fatal error

    With the fix I do not.

  • Status changed to Needs work about 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom catch
    +++ b/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php
    @@ -68,6 +70,20 @@ public function testNoForm() {
    +    $batch['progressive'] = FALSE;
    +    batch_process();
    +    return new RedirectResponse(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString());
    +  }
    

    I was trying to work out if the redirect was necessary for the test, and I think it isn't. Could we make this return a hello world #markup render array or something else minimal?

    Also is a route necessary here? Seems like it could maybe be a kernel test instead?

Production build 0.71.5 2024