Problem/Motivation

Running drush cim -y after drush si --existing-config -y throws a fatal TypeError:

TypeError: Drupal\config_split\Config\ConfigSorter::sortDeep():
Argument #2 ($model) must be of type array, false given, called in
/docroot/modules/contrib/config_split/src/Config/ConfigPatchMerge.php on line 96
in Drupal\config_split\Config\ConfigSorter->sortDeep()
(line 174 of config_split/src/Config/ConfigSorter.php)

Steps to reproduce

  1. Fresh drush si --existing-config -y on a site with config_split enabled
  2. Run drush cim -y immediately after

Proposed resolution

Guard against the false return value from read() before calling sortDeep():

if ($this->active->exists($name)) {
$activeData = $this->active->read($name);
if (is_array($activeData)) {
$data = $this->sortDeep($data, $activeData);
}
}

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

mayurgajar created an issue. See original summary.

dkmishra’s picture

I cannot reproduce this with only drush si --existing-config -y followed by drush cim -y on config_split 2.0.2 / Drupal 11.3.11 / Drush 13.7.3. Could you provide the relevant split configuration, the affected config name, and whether any config_split.* files or partial split configuration are involved? There may be a specific setup detail missing from the reproduction steps.

beunerd made their first commit to this issue’s fork.

beunerd’s picture

Status: Active » Needs review

@dkmishra I was able to reproduce.

ConfigSorter::sort() assumes read() returns an array whenever exists() is TRUE, but read() can still return FALSE (e.g. right after drush si --existing-config), which throws the TypeError.

I added an MR that skips sorting when read() isn't an array (and included a test with a mocked storage).

peri22’s picture

Status: Needs review » Reviewed & tested by the community
peri22’s picture

Confirmed on the current '2.0.x' HEAD. This is tricky to reproduce because 'CachedStorage::exists()' bypasses the cache, while 'read()' answers from it (and can return 'FALSE' for missing objects too). When they disagree, the error occurs. I managed to reproduce the reported 'TypeError' using real storages (no mocks) in two ways, and MR !65 fixes both.

The existing sorter test stays green, 'phpcs' is clean, the MR applies to today's HEAD, and pipeline 927451 is green across all jobs. RTBC.