ConfigInstaller::isSyncing() is not reset before module preinstall

Created on 1 January 2020, over 4 years ago
Updated 6 January 2024, 5 months ago

Problem/Motivation

When modules are being installed during configuration sync, \Drupal::service('config.installer')->isSyncing() returns FALSE in hook_module_preinstall() implementations. This is because the kernel is updated and the container is rebuilt just prior to the preinstall hooks being invoked. The config installer sync status is not set back to TRUE until later.

Proposed resolution

Restore state of ConfigInstaller, including whether it is syncing and its source storage in \Drupal\Core\Extension\ModuleInstaller::updateKernel().

Pass ConfigInstaller::isSyncing value to hook_module_preinstall() and hook_module_preuninstall implementations.

Remaining tasks

(reviews needed, tests to be written or run, documentation to be written, etc.)

API changes

See change record: hook_module_preinstall() and hook_module_preuninstall() now have a second argument $is_syncing β†’

Data model changes

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
ExtensionΒ  β†’

Last updated 3 days ago

No maintainer
Created by

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • Status changed to Needs review 7 months ago
  • First commit to issue fork.
  • Status changed to RTBC 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Rebased to run test-only feature

    1) Drupal\KernelTests\Core\Config\ConfigImporterTest::testIsSyncingInHooks
    \Drupal::isConfigSyncing() returns TRUE
    Failed asserting that null is true.
    /builds/issue/drupal-3103962/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
    /builds/issue/drupal-3103962/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
    /builds/issue/drupal-3103962/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php:848
    /builds/issue/drupal-3103962/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    FAILURES!
    Tests: 23, Assertions: 136, Failures: 1.
    

    Hiding files for clarity.

    Issue summary seems clear about what is being fixed and matches the solution in the MR.

    LGTM!

  • πŸ‡ΊπŸ‡ΈUnited States xjm
  • Status changed to Needs work 6 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Issue credits

    Left some questions on the MR, tl;dr I think hook_module_preuninstall has the same issue and wonder if perhaps we should be doing the fix inside ::updateKernel so it resolves both issues at once.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @larowlan excellent point about uninstall. Install and uninstall should be mirrors.

    I'm slightly dubious about the use-case here because what are you doing in pre-install - really shouldn't be doing anything permanent - so whatever is happening probably should happen regardless of whether we are syncing - but hey workspaces does interesting stuff here but it is inconsistent so +1 to fixing.

    I think we should also consider adding is_syncing to the hook signature to anyone who implements hook_module_preinstall() has to consider the config syncing case.

  • I agree use cases are pretty obscure, and I'm having trouble recalling exactly how it was I ran into it four years ago. I believe that I was working on a project that had an install profile that used Config Rewrite ( https://www.drupal.org/project/config_rewrite β†’ ). That module has an hook_module_preinstall() implementation that I wanted to prevent from happening when installing from existing configuration. Though it looks like between then and now they found a different way to do that detection.

  • Status changed to Needs review 6 months ago
  • Addressed review comment to restore state of config installer in ::updateKernel.
    Added $is_syncing value as second parameter to hook_module_preinstall() and hook_module_preuninstall implementations.
    Updated tests and rebased.
    Added CR and updated IS.

  • Status changed to Needs work 6 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @godotislate - nice work - one tiny nit in a kinda out-of-scope change and this will be rtbc.

  • Status changed to RTBC 6 months ago
  • Applied suggested change and moved to RTBC per last comment.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed ba827d4 and pushed to 11.x. Thanks!

  • Status changed to Fixed 6 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024