Problem/Motivation

After running drush cex with https://www.drupal.org/project/config_ignore/issues/3099674#38 I get this error:

$ drush cex -y
 [error]  TypeError: Argument 1 passed to Drupal\Component\Utility\NestedArray::unsetValue() must be of the type array, null given, called in /web/modules/contrib/config_ignore/src/EventSubscriber/ConfigIgnoreEventSubscriber.php on line 150 in Drupal\Component\Utility\NestedArray::unsetValue() (line 219 of /web/core/lib/Drupal/Component/Utility/NestedArray.php) #0 /web/modules/contrib/config_ignore/src/EventSubscriber/ConfigIgnoreEventSubscriber.php(150): Drupal\Component\Utility\NestedArray::unsetValue(NULL, Array)
#1 /web/modules/contrib/config_ignore/src/EventSubscriber/ConfigIgnoreEventSubscriber.php(96): Drupal\config_ignore\EventSubscriber\ConfigIgnoreEventSubscriber->transformStorage(Object(Drupal\Core\Config\DatabaseStorage), Object(Drupal\config_filter\Config\FilteredStorage))
#2 [internal function]: Drupal\config_ignore\EventSubscriber\ConfigIgnoreEventSubscriber->onExportTransform(Object(Drupal\Core\Config\StorageTransformEvent), 'config.transfor...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#3 /web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\Core\Config\StorageTransformEvent), 'config.transfor...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#4 /web/core/lib/Drupal/Core/Config/ExportStorageManager.php(88): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('config.transfor...', Object(Drupal\Core\Config\StorageTransformEvent))
#5 /web/core/lib/Drupal/Core/Config/ManagedStorage.php(146): Drupal\Core\Config\ExportStorageManager->getStorage()
#6 /web/core/lib/Drupal/Core/Config/ManagedStorage.php(127): Drupal\Core\Config\ManagedStorage->getStorage()
#7 /web/core/lib/Drupal/Core/Config/CachedStorage.php(247): Drupal\Core\Config\ManagedStorage->getAllCollectionNames()
#8 /web/core/lib/Drupal/Core/Config/StorageComparer.php(451): Drupal\Core\Config\CachedStorage->getAllCollectionNames()
#9 /web/core/lib/Drupal/Core/Config/StorageComparer.php(198): Drupal\Core\Config\StorageComparer->getAllCollectionNames()
#10 /vendor/drush/drush/src/Drupal/Commands/config/ConfigExportCommands.php(135): Drupal\Core\Config\StorageComparer->createChangelist()
#11 /vendor/drush/drush/src/Drupal/Commands/config/ConfigExportCommands.php(115): Drush\Drupal\Commands\config\ConfigExportCommands->doExport(Array, '../config/sync')
#12 [internal function]: Drush\Drupal\Commands\config\ConfigExportCommands->export(NULL, Array)
#13 /vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#14 /vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#15 /vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#16 /vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#17 /vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /vendor/symfony/console/Application.php(1005): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#24 /vendor/drush/drush/includes/preflight.inc(18): require('/Volumes/Webdev...')
#25 phar:///usr/local/bin/drush/bin/drush.php(141): drush_main()
#26 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#27 {main}. 
TypeError: Argument 1 passed to Drupal\Component\Utility\NestedArray::unsetValue() must be of the type array, null given, called in /web/modules/contrib/config_ignore/src/EventSubscriber/ConfigIgnoreEventSubscriber.php on line 150 in Drupal\Component\Utility\NestedArray::unsetValue() (line 219 of /web/core/lib/Drupal/Component/Utility/NestedArray.php).
 [warning] Drush command terminated abnormally.

Seems like there's a bug here, $import_data is undefined:

$source_data = $source_storage->read($config_name);
foreach ($keys as $key) {
  NestedArray::unsetValue($import_data, $key);
}

Proposed resolution

Fix the export.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpp created an issue. See original summary.

mpp’s picture

Status: Active » Needs review
FileSize
1.01 KB

Let's see what testbot says.

claudiu.cristea’s picture

Status: Needs review » Needs work
+++ b/src/EventSubscriber/ConfigIgnoreEventSubscriber.php
@@ -146,10 +146,15 @@ class ConfigIgnoreEventSubscriber implements EventSubscriberInterface {
-              NestedArray::unsetValue($import_data, $key);
...
-            $transformation_storage->write($config_name, $import_data);

Thank you for spotting this. This is a bug introduced by me because, initially, that variable was named $import_data. Then I renamed it to $source_data and, it seems, that I forgot 2 occurrences. We only need to replace $import_data with $source_data. There should be no $import_data in the code.

The reason we didn't catch this is because we don't have a test case where we only ignore one ore more keys from a config, rather than ignoring the whole config. Could please extend the ConfigWithTranslationTest test and add another config where we only ignore some keys from that config? Also, post a "test only" patch so we that we can observe the failure.

mpp’s picture

FileSize
1.01 KB

@claudiu.cristea, I had indeed noticed the commit where we refactored $import_data with $source_data.

Updating the patch accordingly. I'd have to look into the tests when I have some more time.

I fear that there's one (or more) regression(s) when compared to https://www.drupal.org/project/config_ignore/issues/2857247;

1. The following ignore config used to work (all layers were ignored, except 'agiv_grb'):
- 'dg_maps.layer.*'
- ~dg_maps.layer.agiv_grb

After the patch from #3099674 'agiv_grb' is no longer ignored but exported. This seems like a bug, should I open another issue for that?

2. I have a config file with ignores (some properties are ignored in myconfig.settings.yml), there is one translation for this config in Dutch (/translations/nl/myconfig.settings.yml) but none for German (/translations/de). The default behavior seems to have been changed by #3099674: /translations/de/myconfig.settings.yml is now also exported. I think this is a bug but I'm not sure what should be the expected behaviour here?

mpp’s picture

FileSize
1.02 KB
mpp’s picture

FileSize
1.01 KB

Sorry for #4 & #5, indentation was wrong for my project. (off-topic rant: I wish I could do this on github/gitlab instead of the patch files :s)

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
10.26 KB
13.02 KB

@mppm, it was only to change the vars. I've already fixed other bug, possible the one you mentioned in #4 and I've extended the test coverage for both bugs. Posting also a "test only" patch.

Status: Needs review » Needs work

The last submitted patch, 7: 3117135-7.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.79 KB
14.22 KB

Fixing tests.

Status: Needs review » Needs work

The last submitted patch, 9: 3117135-9.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.17 KB
14.34 KB

The tests are passing locally,

  • bircher committed 1c179cb on 8.x-3.x
    Issue #3117135 by claudiu.cristea, mpp: TypeError: Argument 1 passed to...
bircher’s picture

Status: Needs review » Fixed

Thanks for the issue and the patch!
I had overlooked the possibility that things can return null, it happened already so many times I wish there was stricter typing like in rust.

Status: Fixed » Closed (fixed)

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