If an update hook modifies configuration, then old configuration is imported, the changes made by the update hook are forever lost.

Created on 31 January 2020, almost 5 years ago
Updated 28 November 2023, 12 months ago

A typical workflow is that developers, on a local version of a site, will update the code, then run:

...
drush updb
drush cim
...

The important thing here is that drush updb is often run before drush cim, and this is the suggested course of action proposed, for example, in:

Where this will fail however when drush updb updates configuration, as happens, for example, when:

We realize, thus, that whatever order we run drush cim, drush updb, and drush cex in, none is foolproof:

This will fail, for example, in the scenario described here:

drush cim
drush updb

This will fail, for example, in the scenario described here πŸ› Undefined property: stdClass::$region in field_group_form_process() Fixed

drush updb
drush cim

Possible resolutions

  • Better documentation?
  • A combined updb/cim command?
  • Warning that drush cex should be run in case config is deemed out-of-date in code?
πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
ConfigurationΒ  β†’

Last updated 2 days ago

Created by

πŸ‡¨πŸ‡¦Canada alberto56

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 markdorison

    This issue recently affected us with the release of Drupal 10.1. πŸ“Œ Replace custom password hashing library with PHP password_hash() Fixed included an update hook to enable the new phpass core module. Once that update hook ran the module was enabled only to be disabled when config import was subsequently run.

    We have automated tests that check the status of Drupal config state, but these did not fail because once config:import had run (via drush deploy), the configuration on disk matched the active configuration as far as Drupal was concerned.

    If we are allowing folks to believe that configuration on disk is their source of truth and then modifying active configuration with an update hook, this seems like it will inevitably cause issues like this.

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

    It seems to me like there's a fundamental contradiction to running database updates and configuration updates all in a single action.

    It's already very complicated to wrestle with the concept of "correct configuration" when you have site administrators making configuration updates and developers making configuration updates in parallel.

    What if configuration updates in code were given special treatment? We could have a separate one-time operation from updb [hook_install_configuration_N(): returns an array of configuration files to be re-imported from a module's /config/*/ directories; is triggered by 'drush update-configuration' or visiting /update-config.php]

    Then, the "best practice" could be:
    1. updb
    2. cim
    3. upcfg

    (and then: export that config into code!)

    If we tracked the executed upcfg functions in their own table with a date or "invocation" column, we could provide a way to "re-run" an invocation if a site accidentally ran CIM after upcfg.

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

    At Lullabot, we wrote up an Architecture Decision Record (ADR) to deal with a similar situation.

    https://architecture.lullabot.com/adr/20210924-drupal-build-steps/

    Depends on developers using hook_post_update_NAME() β†’ .

    Does that help?

  • πŸ‡ΊπŸ‡ΈUnited States moshe weitzman Boston, MA

    A PR is in progress for drush deploy to catch this problem and stop the deployment - https://github.com/drush-ops/drush/pull/5713

Production build 0.71.5 2024