-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entity type provided by a module installed via update hook not available #4103
Entity type provided by a module installed via update hook not available #4103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix and the test coverage! Code looks good and I can replicate the failures.
I have added some documentation suggestions.
Looks good to me, thanks for the contribution! |
Lets hold off on merging this. I want to get an old Pr linked here which touched on this issue, or a similar one. |
I can't find the source of this bug, it might not be a regression. It's very possible that this didn't surfaced. But the proof is there, in the test. |
The issue I was thinking of is #2617 and its PR is #2620. I just mention them in case anyone finds them relevant.
Is it really acceptable to install modules in a post_update hook? I would think that you enable the modules you want to enable locally, and deploy a new core.extension.yml to the higher environments. Perhaps there are other use cases. Also, woot_post_update_install_taxonomy() does't run batches like pm:enable does. See drush/src/Drupal/Commands/pm/PmCommands.php Lines 78 to 83 in 40092d5
Finally, why does the cache-rebuild not fix this - drush/src/Commands/core/UpdateDBCommands.php Lines 425 to 426 in d17e067
|
We are doing this when we are adding a new module dependency to an existing custom module that is optional in our distribution. It is possible users are running a different set of modules than we originally ship the distribution with. We don't control their config but we need to ensure somehow that they will have the module enabled after they update to our latest version. Maybe it is possible to do this in pure config, but I don't know how. |
This is a very interesting suggestion. I investigated this. This section to run the batch processes was added in #3444 to ensure that the translation imports are completed when the Locale module is enabled. Indeed, the Locale module sets a batch in So this means that somehow the Locale module is fine with translations only being imported when the module is enabled as part of a form submit. I could not find any other modules that attempt this, and it doesn't seem likely that the rebuilding of the container is handled in this way. Most probably in the "normal" install procedure (which is I also wanted to understand how core handles the mangled container when performing database updates, since this evidently works fine in core but somehow not in Drush. It turns out that a container rebuild is triggered automatically as part of the update procedure. This is initiated through the call to So I am thinking that it is probably a good idea to copy this behavior to |
* The list of extensions that are installed before updates are applied. | ||
* @var array | ||
*/ | ||
protected $originalExtensionList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this section, we no longer need to track if extensions are updated.
$final_extension_list = \Drupal::config('core.extension')->getRawData(); | ||
if ($final_extension_list !== $this->originalExtensionList) { | ||
// Invalidate the container if the installed extension list has been changed. | ||
\Drupal::service('kernel')->invalidateContainer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's replace this with a simple cache flush:
public static function updateFinished($success, $results, $operations)
{
// Flush all caches. Drupal core does the same after finishing the updates.
// @see \Drupal\system\Controller\DbUpdateController::batchFinished()
drupal_flush_all_caches();
}
/** | ||
* Start the database update batch process. | ||
* @param $options | ||
* @return bool | ||
*/ | ||
public function updateBatch($options) | ||
{ | ||
// Track the currently installed extensions so that we can detect if any | ||
// new extensions are added in the update. | ||
$this->originalExtensionList = \Drupal::config('core.extension')->getRawData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need this any more.
That makes sense to me. We've had that clear and removed it a couple times over the long life of udpatedb. Please add code comments so we dont remove it again. Also, lets review the cache clears already in the command to see if any can now be removed. |
@weitzman @pfrenssen I cannot explain the failure with Windows, it seems unrelated for me and I don't know how to trigger a rebuild. |
The AppVeyor failure seems to be unrelated to this issue, I see that the master is affected by the same problem:https://github.com/drush-ops/drush/commits/master |
Great, looking good to me, thanks! |
I looked into this. There is one other instance where the cache is cleared, in
|
// performs database updates it also clears the cache at the end. This | ||
// ensures that we are compatible with updates that rely on this | ||
// behavior. | ||
drupal_flush_all_caches(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should only run if the option --cache-clear is true. PR can be merged after thats done.
…ilable. Regression test.
Co-Authored-By: Pieter Frenssen <pieter@frenssen.be>
Co-Authored-By: Pieter Frenssen <pieter@frenssen.be>
Co-Authored-By: Pieter Frenssen <pieter@frenssen.be>
@weitzman I've added the check. I had to make |
If an entity type is provided by a module being installed via a (post)update hook. The next Drush command will fail to recognize the new installed definition, unless a cache rebuild is run just after
updatedb
. For example, with this hook:When running:
This will end successfully and will return
taxonomy_term
, but if I run immediately:...will output:
The bug is reproduced in the provided regression test. Rebuilding the cache in between is a workaround. This was not a bug before. We see this happening after moving to Drupal 8.7.x (is it probably related to https://www.drupal.org/node/3034742?)
It's interesting that the post-update recognizes the new installed entity type, as it returns its ID. This is not a Drupal issue. I tested the same scenario by running the UI update and works without error. I also run the next sequence with no errors:
The issue pops-up only when enabling the module via a (post)update.