Problem
When a domain config override is saved with values identical to the default (no real difference), domain_config writes an empty override object ({}) into the domain config collection instead of removing it. This happens routinely when saving a multi-config form, for example the account settings form which edits system.site, user.mail and user.settings: the config names you did not change are written as empty overrides.
These empty overrides then break configuration synchronization: drush cex exports them and drush cim imports them, but they are perpetually reported as modified and never converge. drush cim --diff shows no difference, and there is no way to get rid of them through normal sync.
Steps to reproduce
- Enable a per-domain override on a config (e.g. system.site) for a domain.
- Save the form with values equal to the default, or save a multi-config form like account settings after changing only one of its configs.
- Run
drush cexthendrush cimrepeatedly: the empty override keeps showing as modified, with--diffreporting no difference.
Root cause
In DomainConfigOverrideEditable::save() the override row is the diff against base:
$this->moduleOverrides = DiffArray::diffAssocRecursive($this->data, $base_for_diff); $this->storage->write($this->name, $this->moduleOverrides);
When the diff is empty, write() still persists an empty {} record rather than deleting the override.
Proposed fix
When the computed override is empty, delete any existing override row instead of writing an empty one (cache tag invalidation and the SAVE events should still fire so the removal is reflected):
$this->moduleOverrides = DiffArray::diffAssocRecursive($this->data, $base_for_diff);
if (empty($this->moduleOverrides)) {
if ($this->storage->exists($this->name)) {
$this->storage->delete($this->name);
}
}
else {
$this->storage->write($this->name, $this->moduleOverrides);
}
A follow-up update hook could also purge empty overrides already present in storage.
Reported by hanoii in #3593113 while testing the multi-config registration fix; it is a separate, pre-existing issue in the override save path.
Issue fork domain-3593636
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mably commentedComment #3
mably commentedComment #5
mably commentedComment #6
mably commented@hanoii can you verify that MR 391 fixes the bug you reported?
Comment #8
hanoiiOther than the two related issues I fill in, this particular part seems to be working nicely.
Comment #11
mably commentedMerged. Thanks!