Problem/Motivation
After installing a module via a recipe, the cache needs to be cleared before the module can be used. Failing to do so results in a fatal error.
Steps to reproduce
Given this recipe code:
# a simplified recipe
name: 'Pathauto example recipe'
description: "An example recipe showing the activation of the pathauto module"
type: 'Content'
install:
- pathauto
After installing the recipe using the php script, and receiving a success command, visiting the `/admin/config/search/path` results in an error:
Drupal\Component\Plugin\Exception\PluginException: Plugin (path) instance class "Drupal\pathauto\PathautoItem" does not exist. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 97 of /app/web/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).
Clearing manually the cache (with drush cr for example) returns the site to normal, and I am able to visit the page to set pathauto settings etc.
Proposed resolution
A cache clearing operation could be added after a module is enabled by a recipe?
Issue fork drupal-3315694
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:
- 3315694-cache-could-be
changes, plain diff MR !8473
1 hidden branch
Issue fork distributions_recipes-3315694
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:
- 3315694-cache-broken-after-install
compare
- 11.x
compare
- 3315694-cache-could-be
compare
Comments
Comment #2
vermario commentedComment #3
Anonymous (not verified) commentedanujasurve made their first commit to this issue’s fork.
Comment #4
deviantintegral commentedLooks like this kills the whole site, not just that page.
What's confusing to me is that I would have expected the underlying API to install the module to clear caches. Investigating!
Comment #5
deviantintegral commentedI've been working on this and while I have a "fix", I'm not confident it's the right one.
At a basic level, if we clear all caches in
\Drupal\Core\Recipe\RecipeRunner::processInstall()by callingdrupal_rebuild()after installing modules and themes, everything works fine. I was able to narrow it down rebuilding the container and clearing the cached container definitions by throwing this at the end ofprocessInstall().What's throwing me for a loop is that Drush doesn't have any code like this for it's module install command (
\Drush\Drupal\Commands\pm\PmCommands::install) and doesn't have this problem. I'm not finding any code that rebuilds the container separately. As well, the module installer itself calls\Drupal\Core\DrupalKernel::updateModuleswhich rebuilds the container.Any ideas? On the one hand, given how broken this is I wonder if committing a basic cache clear for now makes sense until we can confirm a proper fix.
Comment #6
sonfdComment #7
wim leersThis came up in #3301370: Model core's standard install profile as recipes — see #3301370-45: Model core's standard install profile as recipes. This is hence a blocker to the Standard install profile getting converted to a Recipe.
I'm somewhat surprised this needs an explicit/manual cache clear … and it seems that @deviantintegral was similarly surprised in #5 with his excellent research 🤓
Comment #8
narendrarSteps to reproduce this issue for standard recipe install:
curl https://git.drupalcode.org/project/distributions_recipes/-/raw/patch/recipe-11.x.patch | git applycurl https://www.drupal.org/files/issues/2024-01-23/recipes-standard-profile-3301370-45.patch | git applydrush si -y emptyphp core/scripts/drupal recipe core/recipes/standardThe website encountered an unexpected error. Try again later.error.drush crComment #9
bibliophileaxe@deviantintegral, I've had the "Plugin does not exist" error pop up even while enabling/disabling modules with drush.
Comment #10
thejimbirch commentedComment #11
prashant.cAfter applying any recipe the site cache should be cleared because every time I apply a recipe the website throws different errors after successful application and only cache clear manually fixed the issues, therefore, IMHO a cache clear should always trigger after applying a recipe.
Thanks!
Comment #14
b_sharpe commentedI can replicate the issue with the given "pathauto" recipe above, but what I find interesting is that I can run:
./vendor/bin/drush php:eval "\Drupal::service('module_installer')->install(['pathauto']);"in the exact same state as before the recipe and I do not see the issue.This leads me to believe something else is at play here since the Recipe is using that same method to install the module. I don't think just killing all cache when applying a recipe is the answer rather than tracking down the cause of this issue.
Comment #15
b_sharpe commentedI found the root cause of this here, in which the RecipeCommand's Kernel was set to not allow writing to the container.
This causes discovery, bootstrap, and container caches to not update from the recipe which is why plugin and entity discovery acts up as well as some routes.
What I'm not sure of is WHY this was specifically set to FALSE as the default for the function is TRUE so I have to assume this was an intentional change at this point, so am holding off on the MR until I can confirm with original committers.
Comment #16
phenaproximaAwesome detective work, @b_sharpe! I think we'll need @alexpott to weigh in here.
Comment #17
phenaproximaComment #18
alexpottI'm pretty sure this is a copy and paste fail from one of the other commands we have that do not install modules. Let's fix this in core and I'll merge into the recipe initiative code base.
Comment #19
alexpottComment #23
b_sharpe commentedAdded MR. Needs tests.
Comment #24
alexpott@b_sharpe and I discussed tests and we agreed that test coverage here is not necessary it is c&p paste fail from our other commands (that do not need to write container) and is really obvious once you see it.
Comment #25
phenaproximaA one-line copypasta bug fix that makes the recipe application process smoother and reduces unexpected exceptions? SOLD! Heartily, I RTBC thee.
Comment #26
alexpottDiscussed with a @catch and we agreed to put this in 10.3.x because it is a doh! copy pasta mistake (mine) and improves the recipe experience tremendously in 10.3.0.
Committed and pushed 34a6368597 to 11.x and 002bca921a to 11.0.x and bd1049d4c4 to 10.4.x and 350464e891 to 10.3.x. Thanks!