Problem/Motivation

The documentation of hook_update_N() says:

The system will stop iterating this update when $sandbox['#finished'] is left unset or set to a number higher than 1.

This is only kind of true because

  1. Iteration also stops if $sandbox['#finished'] == 1
  2. The update process is properly closed only if $sandbox['#finished'] == 1 since in update_do_one() we have:
  // Record the schema update if it was completed successfully.
  if ($context['finished'] == 1 && empty($ret['#abort'])) {
    drupal_set_installed_schema_version($module, $number);
  }

which means if $sandbox['#finished'] is > 1 then the schema_version for the module won't be updated (even if the updates run successfully).

Proposed resolution

Since

  1. according to the documentation 'finished' values > 1 are already allowed and
  2. the batch API does not differentiate between 1 and >1 'finished' values

I think hook_update_N() should not differentiate between 1 and >1 'finished' values either.

Remaining tasks

Review patch.

API changes

Comments

czigor’s picture

czigor’s picture

Status: Active » Needs review
czigor’s picture

Issue summary: View changes
joachim’s picture

Version: 7.x-dev » 8.3.x-dev
Status: Needs review » Needs work

Still a bug on 8.3.x.

chanderbhushan’s picture

StatusFileSize
new509 bytes

Hi,

Added patch for 8.3.x.

thanks

chanderbhushan’s picture

Status: Needs work » Needs review

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Version: 9.3.x-dev » 7.x-dev
Issue tags: +Bug Smash Initiative

This was fixed in 2015 in #2521776: Update documentation for hook_update_N() for Drupal 8. But this is still applicable to Drupal 7. Therefor changing version.

Thanks!

poker10’s picture

Status: Needs review » Needs work

Thanks for working on this.

The patch #1 needs work. We should remove this change, as it was never committed to D8+ and D10 code still has the original code:

-  if ($context['finished'] == 1 && empty($ret['#abort'])) {
+  if ($context['finished'] >= 1 && empty($ret['#abort'])) {

And then we need to compare and verify, if the comment changes are correct per #2521776: Update documentation for hook_update_N() for Drupal 8 (just for the relevant parts). Thanks!

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.