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:
- In ConfigImportSubscriber, check if key exist before foreach
- In ThemeInstaller.php, if the key is the known bad theme, return
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #48 | 2898274-47.patch | 4.05 KB | borisson_ |
Comments
Comment #2
robpowellWell once uninstall() was able to complete, the theme seems to be uninstalled. When I
drush cexthe 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: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.
Comment #4
dietr_ch commentedI noticed the
$listarray is only used for checking base/sub themes. So I moved theisset()check around. Attached is a patch without tests to see what (if anything) fails.Comment #5
dietr_ch commentedComment #7
Keenan47 commentedIs 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.
Comment #8
pektinasen commentedI 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.
Comment #10
johncionci commentedI recently ran into this issue, running
drush updbseemed to work for me.Comment #12
gaëlgIt looks like patch #4 is already in core now.
Comment #13
gaëlgIs it? It's at least not in 8.7.1. Here's a reroll.
Comment #14
aleevasComment #15
aleevasTrying to fix tests (was removed catch of the exception from the test, because we don't use this exception in code anymore)
Comment #16
aleevasNext one
Comment #17
piotrkonefal commentedComment #18
piotrkonefal commentedComment #19
piotrkonefal commentedHere is a re-roll for 8.7.x version.
Comment #21
mrlexington commentedI 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.
Comment #22
aleevasThe latest patch was rerolled to version 8.9
Comment #24
aleevasAdded fix for the latest patch
Comment #25
aleevasSorry, it was a wrong file.
I hope this one will be much better
Comment #27
rp7 commentedI can confirm patch in #25 fixed the issue for me.
Comment #28
aleevasRe-rolled patch up to 9.1
Comment #29
gaëlgHere's a reroll against 8.9.x (applies to 8.9.6).
Comment #31
chegor commented#29 Helped me in 8.9.13
Comment #32
wylbur commentedThis 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?
Comment #34
stevengfxCould not apply patch #28 in 9.1.8
Comment #35
ankithashettyRerolled the patch in #28, thanks!
Comment #36
benjamin.merkley commented#21 Worked for me simple and easy
Comment #37
stefaniev commentedPatch #35 worked for me in Drupal 9.2.5, thanks!
Comment #40
alexpottInitially 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.Comment #42
smustgrave commentedFor the change record mentioned in #40.
Did not test patch.
Comment #44
borisson_Added a basic change record. Keeping this on needs work for the documentation.
Comment #45
borisson_Fixed remarks in #40
Comment #46
smustgrave commentedCR 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?
Comment #47
alexpottI think we should replace this with
So we can only uninstall themes that are listed in the core.extension.
Otherwise this happens:
Comment #48
borisson_Looks like the test coverage changes were also wrong, updated test + code based on #47.
Comment #49
smustgrave commentedManually triggering tests and hiding old patches.
Comment #50
smustgrave commentedAll green. And feedback from #47 has been addressed.
Comment #51
alexpottCommitted and pushed bfc5c6d181c to 11.x and 01b19986028 to 10.2.x. Thanks!
Backported to 10.2.x as a non-disruptive bugfix.