Problem/Motivation

When updating config in an install hook it can produce a recreate changeset in the installer that creates a potential "delete" record which is invalid.

Steps to reproduce

- Install drupal using minimal profile
- Enable views module
- Create a new module called mymodule.
- Create an install file in this module containing this

/**
 * Implements hook_install().
 */
function mymodule_install() {
  \Drupal::configFactory()->getEditable('views.view.content')
    // Make extra double sure this is actually going to update the title, with
    // adding a time factor here.
    ->set('display.default.display_options.title', 'overridden title here' . time())
    ->save();
}

- Enable the mymodule module
- Export the config
- Reinstall the site using existing config (for example with drush si minimal --existing-config -y)

Proposed resolution

Probably make sure we don't produce this changeset?

Remaining tasks

Agree on the approach
Write a patch
Write tests

User interface changes

-

API changes

-

Data model changes

-

Release notes snippet

original report:

Not sure of the precise cause but installing a site with pre-existing config (in this case using "blt setup"in a DrupalVM) can result in invalid IDs which then generate fatal errors.

Error: Call to a member function setSyncing() on null in /var/www/DigitalPlatformCore/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php on line 389 #0 /var/www/DigitalPlatformCore/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(979): Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete('views.view.tmgm...', Object(Drupal\Core\Config\Config), Object(Drupal\Core\Config\Config))
#1 /var/www/DigitalPlatformCore/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(765): Drupal\Core\Config\ConfigImporter->importInvokeOwner('', 'delete', 'views.view.tmgm...')
#2 /var/www/DigitalPlatformCore/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(592): Drupal\Core\Config\ConfigImporter->processConfiguration('', 'delete', 'views.view.tmgm...')
#3 /var/www/DigitalPlatformCore/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(496): Drupal\Core\Config\ConfigImporter->processConfigurations(Array)
#4 /var/www/DigitalPlatformCore/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(239): Drupal\Core\Config\ConfigImporter->doSyncStep('processConfigur...', Array)
#5 /var/www/DigitalPlatformCore/vendor/drush/drush/includes/drush.inc(223): Drush\Drupal\Commands\config\ConfigImportCommands->doImport(Object(Drupal\Core\Config\StorageComparer))
#6 /var/www/DigitalPlatformCore/vendor/drush/drush/includes/drush.inc(214): drush_call_user_func_array(Array, Array)
#7 /var/www/DigitalPlatformCore/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(211): drush_op(Array, Object(Drupal\Core\Config\StorageComparer))
#8 [internal function]: Drush\Drupal\Commands\config\ConfigImportCommands->import('sync', Array)
#9 /var/www/DigitalPlatformCore/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#10 /var/www/DigitalPlatformCore/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#11 /var/www/DigitalPlatformCore/vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#12 /var/www/DigitalPlatformCore/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#13 /var/www/DigitalPlatformCore/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/DigitalPlatformCore/vendor/symfony/console/Application.php(978): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/DigitalPlatformCore/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))
#16 /var/www/DigitalPlatformCore/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/DigitalPlatformCore/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/DigitalPlatformCore/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /var/www/DigitalPlatformCore/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#20 /var/www/DigitalPlatformCore/vendor/drush/drush/drush(4): require('/var/www/Digita...')
#21 {main}
Error: Call to a member function setSyncing() on null in Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete() (line 389 of /var/www/DigitalPlatformCore/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php).

There have been other similar reports but the main associated one is given. This is the relevant method:

  public function importDelete($name, Config $new_config, Config $old_config) {
    $id = static::getIDFromConfigName($name, $this->entityType->getConfigPrefix());
    $entity = $this->load($id);
    $entity->setSyncing(TRUE);
    $entity->delete();
    return TRUE;
  }

In this particular instance, we're trying to delete on non-existent entity but fail if it doesn't already exist. The other methods (importCreate() and importUpdate()) check for a valid entity, this one doesn't. It should.

Issue fork drupal-3051453

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:

  • 3051453-call-to-a Comparechanges, plain diff MR !8354
  • 1 hidden branch
  • 11.x Comparecompare

Comments

adaddinsane created an issue. See original summary.

adaddinsane’s picture

And here's a patch.

superfluousapostrophe’s picture

I found this error while trying to do a config synchronization. The patch in #2 fixed the issue and sync is no longer failing. I am running 8.7.1

adaddinsane’s picture

IGNORE - Wrong patch style.

adaddinsane’s picture

StatusFileSize
new3.4 KB

Found more similar/related issues.

julien’s picture

Here is the patch version that apply for 8.7.x

julien’s picture

hchonov’s picture

Version: 8.6.x-dev » 8.9.x-dev
Status: Active » Needs work
public function importDelete($name, Config $new_config, Config $old_config) {
    $id = static::getIDFromConfigName($name, $this->entityType->getConfigPrefix());
    $entity = $this->load($id);
    $entity->setSyncing(TRUE);
    $entity->delete();
    return TRUE;
  }

In this particular instance, we're trying to delete on non-existent entity but fail if it doesn't already exist. The other methods (importCreate() and importUpdate()) check for a valid entity, this one doesn't. It should.

Adapting this makes sense. But why all the other changes which seem unrelated?

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

rodrigoaguilera’s picture

Status: Needs work » Needs review
StatusFileSize
new2.04 KB

I adapted the patched to have only the relevant parts when there is an invalid id.

Maybe Julien can explain more about those other parts

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

loopy1492’s picture

Heaven knows what combination of modules is causing this problem, but the patch in #10 still works in 9.3

For what it's worth, we just removed Lightning from this site and no other non-lightning site had this problem, so my guess is that's the culprit somewhere.

I know that just blaming lightning is really low-hanging fruit, but hey, if the shoe fits...

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs steps to reproduce, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Can you please provide steps to reproduce this.

This will need a test case to show the issue

Thanks!

loopy1492’s picture

I just had to do this on another site.

I'm not totally sure, but it's possible we're getting this during blt ci due to adding shortcut.set.default to config ignore.

[error]  Error: Call to a member function setSyncing() on null in Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete() (line 379 of /mnt/tmp/local.prod/source/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php) #0 /mnt/tmp/local.prod/source/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(1030): Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete()
#1 /mnt/tmp/local.prod/source/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(816): Drupal\Core\Config\ConfigImporter->importInvokeOwner()
#2 /mnt/tmp/local.prod/source/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(637): Drupal\Core\Config\ConfigImporter->processConfiguration()
#3 /mnt/tmp/local.prod/source/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(541): Drupal\Core\Config\ConfigImporter->processConfigurations()
#4 /mnt/tmp/local.prod/source/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(300): Drupal\Core\Config\ConfigImporter->doSyncStep()
#5 [internal function]: Drush\Drupal\Commands\config\ConfigImportCommands->doImport()
#6 /mnt/tmp/local.prod/source/vendor/drush/drush/includes/drush.inc(122): call_user_func_array()
#7 /mnt/tmp/local.prod/source/vendor/drush/drush/includes/drush.inc(113): drush_call_user_func_array()
#8 /mnt/tmp/local.prod/source/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(271): drush_op()
#9 [internal function]: Drush\Drupal\Commands\config\ConfigImportCommands->import()
#10 /mnt/tmp/local.prod/source/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
#11 /mnt/tmp/local.prod/source/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#12 /mnt/tmp/local.prod/source/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#13 /mnt/tmp/local.prod/source/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(390): Consolidation\AnnotatedCommand\CommandProcessor->process()
#14 /mnt/tmp/local.prod/source/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#15 /mnt/tmp/local.prod/source/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run()
#16 /mnt/tmp/local.prod/source/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand()
#17 /mnt/tmp/local.prod/source/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#18 /mnt/tmp/local.prod/source/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run()
#19 /mnt/tmp/local.prod/source/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun()
#20 /mnt/tmp/local.prod/source/vendor/drush/drush/drush.php(77): Drush\Runtime\Runtime->run()
#21 /mnt/tmp/local.prod/source/vendor/drush/drush/drush(4): require('...')
#22 /mnt/tmp/local.prod/source/vendor/bin/drush(120): include('...')
#23 {main}. 

Error: Call to a member function setSyncing() on null in Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete() (line 379 of /mnt/tmp/local.prod/source/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php).

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

aimevp’s picture

StatusFileSize
new2.04 KB

The patch from #10 would no longer apply for my D10.1.7 installation where I was using it. This is the updated version which applies again on the latest 10.1.x.

rteijeiro’s picture

Tested the #20 patch on:

- Drupal 10.2.4
- OpenID Connect / OAuth client 3.0.0-alpha3
- OpenID Connect Microsoft Azure Active Directory client 2.0.0-beta7

And I get the following error when I go to admin/config/people/openid-connect

TypeError: Drupal\openid_connect\Plugin\OpenIDConnectClientCollection::__construct(): Argument #2 ($instance_id) must be of type string, null given, called in /var/www/web/modules/contrib/openid_connect/src/Entity/OpenIDConnectClientEntity.php on line 142 in Drupal\openid_connect\Plugin\OpenIDConnectClientCollection->__construct() (line 33 of /var/www/web/modules/contrib/openid_connect/src/Plugin/OpenIDConnectClientCollection.php).

Maybe it's totally unrelated but at least the patch applies on Drupal 10.2.4.

eiriksm’s picture

Issue summary: View changes

OK, so here is a minimal reproducible recipe (also updating the IS):

- Install drupal using minimal profile
- Enable views module
- Create a new module called mymodule.
- Create an install file in this module containing this

/**
 * Implements hook_install().
 */
function mymodule_install() {
  \Drupal::configFactory()->getEditable('views.view.content')
    // Make extra double sure this is actually going to update the title, with
    // adding a time factor here.
    ->set('display.default.display_options.title', 'overridden title here' . time())
    ->save();
}

- Enable the mymodule module
- Export the config
- Reinstall the site using existing config (for example with drush si minimal --existing-config -y)

eiriksm’s picture

Opened a MR with another approach, also working for me.

I have a feeling that we are sort of working against an anti pattern for example in contrib here, so not totally sure this is needed. However, it's probably going to continue happening, so it's nice to guard against it at least.

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

kriboogh’s picture

Since both patches (#20 and #24) deal with fixing this issue at different stages in the import sync by adding better code checks, I combined both into the MR. Also added the patch for the MR as it stands now to use in composer.

kriboogh’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs steps to reproduce

Can the proposed solution be verified please

Moving to NW for that and the tests

Steps appear to be added so removing that tag

Thanks.

tushar1’s picture

StatusFileSize
new2.77 KB

Created patch from MR

tushar1’s picture

StatusFileSize
new1.84 KB
ydahi’s picture

Patch in #20 applied to 10.2.6 and helped me get out of this mess.

kenorb’s picture

Same error on config:import on Drupal 10.4.5.

 [error]  Error: Call to a member function setSyncing() on null in Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete() (line 383 of /var/www/html/drupal/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php) #0 /var/www/html/drupal/web/core/lib/Drupal/Core/Config/ConfigImporter.php(1068): Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete()
#1 /var/www/html/drupal/web/core/lib/Drupal/Core/Config/ConfigImporter.php(851): Drupal\Core\Config\ConfigImporter->importInvokeOwner()
#2 /var/www/html/drupal/web/core/lib/Drupal/Core/Config/ConfigImporter.php(672): Drupal\Core\Config\ConfigImporter->processConfiguration()
#3 /var/www/html/drupal/web/core/lib/Drupal/Core/Config/ConfigImporter.php(570): Drupal\Core\Config\ConfigImporter->processConfigurations()
#4 /var/www/html/drupal/vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(259): Drupal\Core\Config\ConfigImporter->doSyncStep()
#5 /var/www/html/drupal/vendor/drush/drush/includes/drush.inc(62): Drush\Commands\config\ConfigImportCommands->doImport()
#6 /var/www/html/drupal/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array()
#7 /var/www/html/drupal/vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(230): drush_op()
#8 [internal function]: Drush\Commands\config\ConfigImportCommands->import()

Patch from #30 seems to fixed the error.

borisson_’s picture

The patches in #30 and #29 seem to be identical to #26.

I am not sure if the solution in there is actually a good one. There are good steps to reproduce, but I would like to get input from one of the config or entity system maintainers on the direction before writing tests.

petar_basic’s picture

StatusFileSize
new2.94 KB

Patch for Drupal 11.3

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

damienmckenna changed the visibility of the branch 11.x to hidden.