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.
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | 3051453_Drupal_11_3.diff | 2.94 KB | petar_basic |
| #30 | Drupal_10_3.patch | 1.84 KB | tushar1 |
| #26 | 3051453-24-MR8354.diff | 2.94 KB | kriboogh |
| #5 | protect_against_invalid_ids_in_import_delete-3051453-3.patch | 3.4 KB | adaddinsane |
| #2 | protect_against_invalid_ids_in_import_delete-3051453-1.patch | 759 bytes | adaddinsane |
Issue fork drupal-3051453
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
adaddinsaneAnd here's a patch.
Comment #3
superfluousapostrophe commentedI 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
Comment #4
adaddinsaneIGNORE - Wrong patch style.
Comment #5
adaddinsaneFound more similar/related issues.
Comment #6
julien commentedHere is the patch version that apply for 8.7.x
Comment #7
julien commentedComment #8
hchonovAdapting this makes sense. But why all the other changes which seem unrelated?
Comment #10
rodrigoaguileraI adapted the patched to have only the relevant parts when there is an invalid id.
Maybe Julien can explain more about those other parts
Comment #14
loopy1492 commentedHeaven 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...
Comment #17
smustgrave commentedThis 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!
Comment #18
loopy1492 commentedI 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.
Comment #20
aimevpThe 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.
Comment #21
rteijeiro commentedTested 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.
Comment #22
eiriksmOK, 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
- Enable the mymodule module
- Export the config
- Reinstall the site using existing config (for example with drush si minimal --existing-config -y)
Comment #24
eiriksmOpened 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.
Comment #26
kriboogh commentedSince 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.
Comment #27
kriboogh commentedComment #28
smustgrave commentedCan the proposed solution be verified please
Moving to NW for that and the tests
Steps appear to be added so removing that tag
Thanks.
Comment #29
tushar1 commentedCreated patch from MR
Comment #30
tushar1 commentedComment #31
ydahiPatch in #20 applied to 10.2.6 and helped me get out of this mess.
Comment #32
kenorb commentedSame error on config:import on Drupal 10.4.5.
Patch from #30 seems to fixed the error.
Comment #33
borisson_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.
Comment #34
petar_basic commentedPatch for Drupal 11.3