Problem/Motivation

During an attempted drush cim, I get the following error messages:

array_keys() expects parameter 1 to be array, null given ConfigImportSubscriber.php:173 [warning]
Invalid argument supplied for foreach() ConfigImportSubscriber.php:173

and

exception 'InvalidArgumentException' with message 'Unknown theme: w2w.' in [error]
/Users/rppowell/Sites/women2women/core/lib/Drupal/Core/Extension/ThemeInstaller.php:220

This theme has been uninstalled but it looks like it has gotten stuck in config. I have tried different strategies to find the corrupt data but so far no luck. Here are some suggestions from people in slack channel and various pages which I have tried.

  • Confirmed theme was uninstalled
  • Searched config files for dependencies to the theme
    • Ran queries to check database
    • select * from key_value where collection = 'state' and name = 'system.theme.files';
    • select name from config where name like ('%theme%');

Using xdebug I have determined that these lines are what are retrieving the corrupt data.

ConfigImportSubscriber.php#171

$uninstalls = $config_importer->getExtensionChangelist('theme', 'uninstall');

ThemeInstaller.php#214

public function uninstall(array $theme_list) {

I cannot determine what calls uninstall but it is after the batch kicks off. Just to clarify, if I do a drush cex w2w is listed under themes. If I try to delete that record and drush cim I will get this error. I would love it if someone could clarify how $config_importer is getting the theme name.

Unfortunately, I am at the point where I don't know how else to troubleshoot this and am starting to get really opinionated about why I don't think a deleted theme should break CIM. I will supply a patch on whatever work-around I commit to but really hoping to learn how to fix this the right way.

Proposed resolution

Two solutions:

  1. In ConfigImportSubscriber, check if key exist before foreach
  2. In ThemeInstaller.php, if the key is the known bad theme, return

Remaining tasks

User interface changes

API changes

Data model changes

Comments

robpowell created an issue. See original summary.

robpowell’s picture

Well once uninstall() was able to complete, the theme seems to be uninstalled. When I drush cex the theme record is no longer there. So I could of broken something or fixed my issue still a little unclear at the moment. Rather than a patch, here is the temporary code I added to get uninstall() to complete:

public function uninstall(array $theme_list) {
    $extension_config = $this->configFactory->getEditable('core.extension');
    $theme_config = $this->configFactory->getEditable('system.theme');
    $list = $this->themeHandler->listInfo();
    foreach ($theme_list as $key) 
      // Corrupt theme data no longer blocks CIM.
      // @todo Determine how to get rid of corrupt theme config.
      if (!isset($list[$key])) {
        // throw new \InvalidArgumentException("Unknown theme: $key.");
        return;
      }

Also determined that the uninstall method was being envoked by ThemeHandler#173. I will tread lightly and test the site but my issue might be fixed.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dietr_ch’s picture

StatusFileSize
new1.37 KB

I noticed the $list array is only used for checking base/sub themes. So I moved the isset() check around. Attached is a patch without tests to see what (if anything) fails.

dietr_ch’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: 2898274-4-notests.patch, failed testing. View results

Keenan47’s picture

Is there any other way around this issue? I've been having it as well on a project I'm assigned to.

We would like to apply this patch if it is stable enough, or if anyone has other recommendations on fixes they would be much appreciated.

pektinasen’s picture

I was able to apply the patch in #4 and I was able to import my config again.

It seems everything works fine. Cannot guarantee there are any sideeffects.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

johncionci’s picture

I recently ran into this issue, running drush updb seemed to work for me.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gaëlg’s picture

It looks like patch #4 is already in core now.

gaëlg’s picture

StatusFileSize
new1.37 KB

Is it? It's at least not in 8.7.1. Here's a reroll.

aleevas’s picture

Version: 8.6.x-dev » 8.7.x-dev
aleevas’s picture

StatusFileSize
new3.31 KB
new2.78 KB

Trying to fix tests (was removed catch of the exception from the test, because we don't use this exception in code anymore)

aleevas’s picture

Version: 8.7.x-dev » 8.8.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.92 KB
new2.39 KB

Next one

piotrkonefal’s picture

StatusFileSize
new2.93 KB
piotrkonefal’s picture

StatusFileSize
new2.97 KB
piotrkonefal’s picture

StatusFileSize
new2.96 KB

Here is a re-roll for 8.7.x version.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mrlexington’s picture

I ran into what sounds like a very similar issue. I solved it by recreating a directory and my_theme.info.yml for the offending no-longer existent theme in my dev site. I cleared the caches and went to the appearance page in the UI (/admin/appearance). There I uninstalled the offending theme and then exported the configuration. I then imported the configuration on my production site and the original errors complaining about the missing theme no longer appeared and the configuration imported successfully.

aleevas’s picture

StatusFileSize
new3 KB
new3.39 KB

The latest patch was rerolled to version 8.9

Status: Needs review » Needs work

The last submitted patch, 22: 2898274-22.patch, failed testing. View results

aleevas’s picture

Status: Needs work » Needs review
StatusFileSize
new2.99 KB
new1.15 KB

Added fix for the latest patch

aleevas’s picture

StatusFileSize
new3 KB
new1.15 KB

Sorry, it was a wrong file.
I hope this one will be much better

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.

rp7’s picture

I can confirm patch in #25 fixed the issue for me.

aleevas’s picture

StatusFileSize
new2.97 KB

Re-rolled patch up to 9.1

gaëlg’s picture

StatusFileSize
new2.99 KB

Here's a reroll against 8.9.x (applies to 8.9.6).

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.

chegor’s picture

#29 Helped me in 8.9.13

wylbur’s picture

This is still a problem for me as I cannot patch core because the site is part of a major university provided service.

Any way to get this reviewed and committed?

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.

stevengfx’s picture

Could not apply patch #28 in 9.1.8

ankithashetty’s picture

StatusFileSize
new2.9 KB
new3.07 KB

Rerolled the patch in #28, thanks!

benjamin.merkley’s picture

#21 Worked for me simple and easy

stefaniev’s picture

Patch #35 worked for me in Drupal 9.2.5, thanks!

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.

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.

alexpott’s picture

Issue tags: +Needs change record

Initially I was going to add a comment saying we don’t support uninstalling themes without code because it’s the same as modules… and then I thought about it and I’m not sure that this is correct. Like theme’s don’t support hook_uninstall() so why shouldn’t we let them be uninstalled if they are not present. So maybe this is reasonable. I certainly think if we do this we need more documentation in \Drupal\Core\Extension\ThemeInstallerInterface::uninstall() and we need to update it because it is no longer throwing an \Drupal\Core\Extension\Exception\UnknownExtensionException exception. Plus we'll need a change record.

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

For the change record mentioned in #40.

Did not test patch.

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.

borisson_’s picture

Added a basic change record. Keeping this on needs work for the documentation.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new3.97 KB
new1.07 KB

Fixed remarks in #40

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

CR has been added, in addition to the added comments.

Manually ran the tests and all green.

Could this of been used between 9 and 10 to uninstall classy?

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Extension/ThemeInstaller.php
@@ -266,9 +266,6 @@ public function uninstall(array $theme_list) {
-      if (!isset($list[$key])) {
-        throw new UnknownExtensionException("Unknown theme: $key.");
-      }

I think we should replace this with

      if ($extension_config->get("theme.$key") === NULL) {
        throw new UnknownExtensionException("Unknown theme: $key.");
      }

So we can only uninstall themes that are listed in the core.extension.

Otherwise this happens:

vendor/bin/drush thun blah                                                                                                                                                           
 [warning] The following theme is missing from the file system: blah ExtensionPathResolver.php:63
 [success] Successfully uninstalled theme: blah
borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new4.05 KB
new1.84 KB

Looks like the test coverage changes were also wrong, updated test + code based on #47.

smustgrave’s picture

Manually triggering tests and hiding old patches.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

All green. And feedback from #47 has been addressed.

alexpott’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed bfc5c6d181c to 11.x and 01b19986028 to 10.2.x. Thanks!

Backported to 10.2.x as a non-disruptive bugfix.

  • alexpott committed bfc5c6d1 on 11.x
    Issue #2898274 by aleevas, piotrkonefal, borisson_, GaëlG, ankithashetty...

  • alexpott committed 01b19986 on 10.2.x
    Issue #2898274 by aleevas, piotrkonefal, borisson_, GaëlG, ankithashetty...

Status: Fixed » Closed (fixed)

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