Drupal does not recognize when the config is identical

Created on 11 October 2024, 6 days ago

Problem/Motivation

I wrote a recipe that included config files in the config directory. I applied the recipe to my site. When I immediately tried to apply it again, I got "The configuration 'CONFIG_ID' exists already and does not match the recipe's configuration". The config cannot have actually changed, so Drupal ought to think they are identical. I suspect this is because of key order, in a similar way to how a config export can sometimes create a big diff in the config files but the changes are all changing the order of the lines, not making any change that actually matters.

Steps to reproduce

Create a recipe with config in the config directory. Apply it to a site twice.

Proposed resolution

Improve the config comparison algorithm so that key order does not cause it to think the config is different. Perhaps this should be done by sorting the keys before comparison. There may be some config for which the order matters. There would need to be a way of recording what config is like this.

Remaining tasks

Implement.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

recipe system

Created by

πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

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

Comments & Activities

  • Issue created by @Liam Morland
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    What was the config file you imported?

    And what did that config file look like when you exported it after recipe application?

    This is most likely invalid configuration. Recipes validation is very strict and can often find invalid config, even when core does not.

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    I observed the problem with dozens of config files generated by drush config-export. In some cases, the only difference in the config files is the value of default_config_hash.

  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Can you please provide specific examples?

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    We are experimenting with a recipe that installs focal_point. The recipe contains this as config/crop.type.focal_point.yml:

    uuid: 1c7db39b-83ff-426c-a193-e247cd89027b
    langcode: en
    status: true
    dependencies: {  }
    _core:
      default_config_hash: flCi9IdafdLXlJqvoHguutUOiC05-aynK4niYN4YZ3o
    id: focal_point
    label: 'Focal point'
    description: 'Crop type used by Focal point module.'
    aspect_ratio: ''
    soft_limit_width: null
    soft_limit_height: null
    hard_limit_width: null
    hard_limit_height: null
    

    After applying the recipe and running, drush config-export, the following crop.type.focal_point.yml file exists in the config sync directory:

    uuid: 1c7db39b-83ff-426c-a193-e247cd89027b
    langcode: en
    status: true
    dependencies: {  }
    _core:
      default_config_hash: DufXX5yd2xSMN-A2aikottVXv2CaBUYzt5kW6m5EXvg
    id: focal_point
    label: 'Focal point'
    description: 'Crop type used by Focal point module.'
    aspect_ratio: ''
    soft_limit_width: null
    soft_limit_height: null
    hard_limit_width: null
    hard_limit_height: null
    

    The only difference between these is the value of default_config_hash.

    If I try to run the recipe again, it says:

    The configuration 'crop.type.focal_point' exists already and does not match the recipe's configuration

  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    ok! Config in the config folder is strict. It is the similar to if you were to try to install a module and the config/install/crop.type.focal_point.yml already existed the module installation would fail.

    Just merged into Drupal 10.4, you can set strict to false, and it will skip passed it.

    config:
      strict: false

    Some other notes:

    - You don't need to copy paste config that are provided by modules into your config folder. That config comes from the focal point module, you should import that from the module.

    - When you do put config in your config folder, you should remove the UUID and _core: default_config_hash:

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    I don't want it to skip past that config. The point of applying the recipe is to make the site be configured the way the recipe calls for. If it skips past, it the recipe will say it was applied when it was not, at least in any useful sense.

    I gave crop.type.focal_point as an example. There were other files that exhibit this problem which are not the default config of any module.

    It would be helpful if there was some kind of recipe validator or warning message so that developers know to remove uuid and _core: default_config_hash from the config.

    But even if those keys are there, they should not be included in the config comparison. This issue is about removing unnecessary comparisons which result in Drupal falsely raising the "exists already and does not match" error.

Production build 0.71.5 2024