Problem/Motivation

I did a update from opigno_lms 8.x-2.11 (search api 8.x-1.10) to opigno_lms 8.x-2.12 (search api 8.x-1.16)

On the database update i got 6 warnings "Warning: Division by zero"

Warning: Division by zero in Drupal\search_api\Task\TaskManager->processBatch() (Zeile 353 in /web/modules/contrib/search_api/src/Task/TaskManager.php)

AFAIK, the check in the patch

> + && in_array(MAINTENANCE_MODE, ['install', 'update'])) {

covers installing Drupal itself and running updates, but it doesn't cover installing a module.

Issue fork search_api-3151796

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Corn696 created an issue. See original summary.

drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new644 bytes

Huh, very strange. Looking at the code, it should be pretty much impossible that this happens.
While we could easily guard against this with some additional checks, I think the better solution would be just to not execute our own batch operations during an update hook. Doesn’t seem like a good idea, generally, I’d say.
Patch attached. Would be great if you could verify that this helps – but probably not really/easily possible.

drunken monkey’s picture

Any feedback on this? Either after testing whether it works, or just general opinion on whether this makes sense?

drunken monkey’s picture

Title: warning Division by zero on database update 1.10 to 1.16 » Problems when executing Search API tasks during database updates

Changing the title so others may find this.

taran2l’s picture

Version: 8.x-1.16 » 8.x-1.x-dev

Seeing this issue while other module is being enabled, the provided patch does not help. Using Search API 1.23

rajeshreeputra’s picture

Status: Needs review » Needs work

same issue with 1.27 release while enabling search_api module in batch from UI.

rajeshreeputra’s picture

rajeshreeputra’s picture

Title: Problems when executing Search API tasks during database updates » Problems when executing Search API tasks during install, updates
drunken monkey’s picture

Status: Needs work » Needs review

Thanks for the feedback, unfortunate that this still didn’t help.
Please see the attached patch for whether this works for you.

@ Rajeshreeputra: Thanks for your patch, also a good attempt! However, under these strange circumstances, I’d rather still execute any tasks we can find/load, and just guard against the division by zero error.

drunken monkey’s picture

Sorry, seems I forgot to actually attach my patch. Please test/review!

drunken monkey’s picture

StatusFileSize
new777 bytes
new1.31 KB

Oops, logic in the else branch was the wrong way round. Let’s also ensure that the total number of items cannot be less than $pending.

drunken monkey’s picture

Would anyone be willing/able to test this, please, to make sure this actually solves the problems?

vaidas_a’s picture

Patch #11 worked for me.

In my case I was receiving an error when importing configuration:
ResponseText: DivisionByZeroError: Division by zero in Drupal\search_api\Task\TaskManager->processBatch() (line 373 of C:\DEV\Projects\intranet\intranet-sources\modules\contrib\search_api\src\Task\TaskManager.php).

After applying the patch I didn't receive this error anymore.

Thank you

  • drunken monkey committed 73190551 on 8.x-1.x
    Issue #3151796 by drunken monkey: Fixed problems when executing Search...
drunken monkey’s picture

Status: Needs review » Fixed

Good to hear, thanks a lot for reporting back!
Committed. Thanks again, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rajeshreeputra’s picture

When can we expect this to be released, Thanks!!

joachim’s picture

Issue summary: View changes

I'm not sure this will completely fix the bug.

I got:

> ResponseText: The website encountered an unexpected error. Try again later.DivisionByZeroError: Division by zero in Drupal\search_api\Task\TaskManager->processBatch() (line 370 of modules/contrib/search_api/src/Task/TaskManager.php). _batch_process() (Line: 138)

when installing the https://github.com/localgovdrupal/localgov_directories module.

ericdsd’s picture

@Joachim did you apply the patch as the commit is not in a release yet ?

vipin.mittal18’s picture

This has been released at search_api version 8.x-1.32