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

  1. Enable a per-domain override on a config (e.g. system.site) for a domain.
  2. 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.
  3. Run drush cex then drush cim repeatedly: the empty override keeps showing as modified, with --diff reporting 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

Command icon 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

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review
mably’s picture

@hanoii can you verify that MR 391 fixes the bug you reported?

hanoii’s picture

Other than the two related issues I fill in, this particular part seems to be working nicely.

  • mably committed 14beffb4 on 3.x
    fix: #3593636 Empty domain config overrides are saved as {} instead of...

  • mably committed c98e4f72 on 3.0.x
    fix: #3593636 Empty domain config overrides are saved as {} instead of...
mably’s picture

Status: Needs review » Fixed

Merged. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.