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.
Comments
Comment #2
thejimbirch commentedWhat 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.
Comment #3
liam morlandI 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 ofdefault_config_hash.Comment #4
thejimbirch commentedCan you please provide specific examples?
Comment #5
liam morlandWe are experimenting with a recipe that installs
focal_point. The recipe contains this asconfig/crop.type.focal_point.yml:After applying the recipe and running, drush config-export, the following
crop.type.focal_point.ymlfile exists in the config sync directory:The only difference between these is the value of
default_config_hash.If I try to run the recipe again, it says:
Comment #6
thejimbirch commentedok! 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.
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:
Comment #7
liam morlandI 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_pointas 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
uuidand_core: default_config_hashfrom 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.
Comment #8
wim leersI created a precise bug report at #3532271: \Drupal\Core\Recipe\ConfigConfigurator unsets the uuid of active configuration, but it should only do that if the recipe data does not contain a UUID that I believe would've prevented #5.
Comment #9
thejimbirch commentedClosing as a duplicate of #3532271: \Drupal\Core\Recipe\ConfigConfigurator unsets the uuid of active configuration, but it should only do that if the recipe data does not contain a UUID