Problem/Motivation
I noticed something strange today with configuration synchronisation. When we deploy configuration that contains both the enabling of a (contrib/core) module & the config from it it doesn’t seem to work. The module appears to get enabled, and the configuration gets imported, but in the end the module really isn’t enabled, although the status in the modules overview screen shows it is enabled. Uninstalling & re-enabling the module & re-importing the config fixes this, but it’s strange as it happened to me twice today.
Encountered on the following stack:
PHP: 7.3
Drupal Core: 8.8.3
Drush: 10.2.2
Drupal Console: 1.9.4
EDIT
The issue seems to only happen when you are not using the Drupal batch UI interactive batch runner.
config import via drush cim --> fail
config import via drupal console ci --> fail
config import via UI --> works
So this seems to be related to the way how batch imports handled.
Steps to reproduce
I encountered the issue twice today on 2 different sites for 2 different modules (jsonapi_extras / media_library), below are the 2 scenarios written out.
jsonapi_extras
- locally enabled the module (drush en)
- locally configured some overrides
- locally exported the configuration (drush cex -y)
- committed and merged on our test branch that triggers a build & deploy
- on the server the configuration is imported (should enable & configure the module)
- config import done & cache is cleared --> no errors
- checked the json:api confiugration --> FAIL: No json:api extras tab
- checked the module overview --> module is enabled --> not true...
- on the server drush pm:uninstall the module
- on the server drush en the module
- on the server drush cim -y (lists all the changes again for the module)
- now it works fine
media_library
- locally enabled the module (drush en)
- locally configured some fields to use the media widget
- locally exported the configuration (drush cex -y)
- committed and merged on our test branch that triggers a build & deploy
- on the server the configuration is imported (should enable & configure the module)
- config import done & cache is cleared --> no errors
- checked the field configuration --> FAIL: The fields don't have the media library widget selected, nor is it available
- checked the module overview --> module is enabled --> not true...
- on the server drush pm:uninstall the module
- on the server drush en the module
- on the server drush cim -y (lists all the changes again for the module)
- now it works fine
Proposed resolution
This occurs with Drush 10 since the config import commands incorrectly use the UpdateKernel. See https://github.com/drush-ops/drush/pull/4217 for more.
This also occurs with Drupal Console - see https://github.com/hechoendrupal/drupal-console/issues/4235
However, this issue also shows that drupal_flush_all_caches() has a problem when rebuilding the container if a new module has been added to core.extension:module configuration. The patch on this issue addresses this weakness.
Remaining tasks
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
None
Comment | File | Size | Author |
---|---|---|---|
#44 | 3119373-9.x-44.patch | 1.94 KB | alexpott |
#44 | 9.x-interdiff.txt | 712 bytes | alexpott |
#44 | 3119373-8.x-44.patch | 1.95 KB | alexpott |
#36 | 3119373-36.patch | 1.95 KB | alexpott |
#36 | 3119373-test-only.patch | 1.14 KB | alexpott |
Comments
Comment #2
Pascal- CreditAttribution: Pascal- commentedRan into this several times as well, first noticed this in 8.8.2
Comment #3
BramDriesenGoing to set this to critical as it looks like even just enabling a module doesn't work anymore.
Comment #4
BramDriesenI have the feeling it might have something to do with this change that is listed in none of the release notes #3043455: Add an API for installing a fieldable entity type (or I'm really looking over it)
Comment #5
BramDriesenI just came to an interesting conclusion:
config import via drush cim --> fail
config import via UI --> works
So is there anything specific to doing an import using the cli vs doing it in the UI ?
Comment #6
cilefen CreditAttribution: cilefen as a volunteer commentedIf it turns out to only affect Drush, let the maintainers know: https://github.com/drush-ops/drush/issues
Comment #7
BramDriesenFYI: I also reported this to the drush issue queue since it might be related to drush only, https://github.com/drush-ops/drush/issues/4350
Comment #8
jungleSubscribing. Would be great if someone to have a check against Drupal Console which has similar commands to Drush.
Comment #9
BramDriesenI'll test that tomorrow, I totally forgot to test this with Drupal Console.
Comment #10
BramDriesenOn Drupal Console I have the same issue, I'll update the description a bit to reflect this. The Drush maintainer said the following:
So since it's seems to happen on both Drush & Console I still feel it's a Drupal Core issue.
Comment #11
BramDriesenComment #12
alexpottThis issue needs to be updated with Drush and console versions so that we can try to reproduce the issue.
Comment #13
alexpottI've tried to reproduce this on Drupal 8.9.x and Drush 9.8.0-dev and the jsonapi_extras module is been successfully installed and the overrides I've created are being imported.
Comment #14
alexpottOut of interest is the site in question using core provided caches or a something different?
Comment #15
BramDriesenHi Alexpott,
Everything is on the latest version, meaning:
Drupal Core: 8.8.3
Drush: 10.2.2
Drupal Console: 1.9.4
To your question of caching, regular caching has been used, no other cache related modules.
Comment #16
BramDriesenComment #17
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedDoes it fail manually, or is it only with the build script? Might seem a stupid question maybe, but you never know something is going wrong in the build script (some leak somewhere, just a guess for now).
Comment #18
BramDriesenFails in both cases actually, both manual drush commands as our ansible script that executes the commands on the server.
E.g. when manually doing the following it fails (repeatably):
Comment #19
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedAnd it also fails with just core and json api only? Sorry for too much questions, just trying to isolate :)
The reason I'm asking is because something else might be in the way, e.g. some other config module or so, maybe even custom code?
Comment #20
BramDriesenI'll try to reproduce it on a clean up-to-date drupal installation this evening.
But the thing is I encountered it on 3 different websites :/ we do have the configuration translation & config ignore modules enabled
(from core.extension.yml)
Comment #21
BramDriesenAnother test I did was to only import the core.extension.yml file by copy pasting it into a partial directory:
drush cim --partial --source=../config/sync/partial/
Which also failed. So the complete scenario was like:
- drush pm:uninstall module
- drush cim --partial --source=../config/sync/partial/
- drush cr
While manually enabling the module works
- drush pm:uninstall module
- drush en module
- drush cr
Comment #22
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedI'm afraid that one of those additional config (or maybe a combination) modules will cause the fail.
Comment #23
BramDriesenNope, I was just able to reproduce it on a clean Drupal installation.
Here is the full & complete setup of what I did.
- composer create-project drupal-composer/drupal-project:8.x-dev config_issue --no-interaction
- Installed through the UI using the standard profile
- After installation I did a drush status with the following output
Okay good, next step:
- composer require drupal/jsonapi_extras
- lando drush en -y jsonapi_extras
- In the configuration I just created one override for the first item shown (block)
- drush cex -y
Now the magical part to prove that it's not working
- drush pm:uninstall jsonapi_extras
- drush cim -y
- drush cr
It doesn't work, the configuration is imported, but no jsonapi_extras tab anymore in the UI.
Comment #24
catch#23 Doesn't entirely prove that configuration import is failing, it proves that the tab for jsonapi_extras isn't showing up after configuration import.
For example if drush cex doesn't show any changes, then the configuration import probably finished successfully.
Can you try things like going to
/admin/config/services/jsonapi/extras
directly?Comment #25
alexpottI can repeat the test but it only occurs for me on Drush 10 and not Drush 9. That's still not saying this is Drush's fault but there is something different in the way that D9 and D10 do things that's resulting in this bug.
On D10 the module is installed and there are no config changes to import but the route doesn't work and even doing a cache rebuild via the UI doesn't work. I considered that maybe this was something in APCu so I disabled that - didn't fix it either. V interesting.
Comment #26
alexpottSo one sign of the problem is that jsonapi_extras has not made it into the container.modules parameter. Which is why it's not in the router.
Comment #27
alexpottSo the patch attached allows drush cache-rebuild to fix the problem but it doesn't actually fix the problem on import.
Comment #28
BramDriesenTo #24
That's probably correct, but if none of the module code is being executed, it doesn't really add any value :-D
#27 I tested it and it fixed the issue on my clean drupal installation test stack! I'll go ahead and also test this on my other sites.
Comment #29
alexpottOk I know what has broken this in Drush. For some reason they've decide to use the UpdateKernel for running config import. Core does not do this and have no idea why they've chosen to do this. Here's one possible fix for Drush - just don't use the update kernel. Config updates are not database updates they are not meant to use that kernel. An alternative approach would be to force flush all the caches after config import. Note that core does not do this because it is not necessary because it uses the regular kernel.
Comment #31
BramDriesen#30 :)
Comment #32
alexpott@BramDriesen that's a patch for Drush that fixes the issue. It'll never pass on core :) and Drush works via github. The issue that has caused this problem is https://github.com/drush-ops/drush/pull/4217
Comment #33
BramDriesenThe patch of #27 is for Drupal core and failed the tests in #30 :-) the patch of #29 for drush and obviously won't apply to Drupal Core no ;-)
Comment #34
BramDriesenSince it also failed with Drupal Console, I can only assume it would also be wrongly implemented there? Although Drush is the most popular option, I'll also open an issue in their issue queue tomorrow.
Back to this issue, I assume it would be okay to make the change of #27 and commit it to core once the tests are passing.
Comment #35
alexpottHere's a fix for #27. I think this change makes sense as it means that the module list is coming from a single source of truth and that's the
extension.list.module
service.Comment #36
alexpottHere's test coverage.
Comment #38
BramDriesenThe patch works fine! Thanks a lot @alexpott !
FYI: I created a similar issue in the Drupal Console issue queue so they can also have a look at it.
Comment #39
alexpottUpdated the issue summary to reflect the solution and where the real problem is. This patch is a mitigation the real fix has to be in Drush 10 and Drupal Console.
Comment #40
BramDriesenYes :-) sounds good to me. Should the patch also be included in 8.9.x and 9.x ?
Comment #41
alexpottComment #42
catchTest failures in 36, against 8.9.x and 9.0.x are real - couple of different ones.
Comment #43
alexpottAh yeah we'll need a different patch for 9.0.x because path_alias is not always installed there.
Comment #44
alexpottI don't think the test failure against 8.9.x is real - that's from Tuesday and one of HEAD fails that day but the 9.x one is real. Here's new patches. the 8.x patch is the same as #36.
Comment #45
tim.plunkettThe fix looks good, tests look good for their respective versions.
Not visible in the patch, but for reference, that variable comes from above:
Comment #46
BramDriesenRTBC For me as well :-)
Comment #50
catchCommitted/pushed to 9.0.x, 8.9.x, and 8.8.x, thanks!
Comment #51
BramDriesenThanks all!
Comment #52
thhafner CreditAttribution: thhafner commentedThanks to everyone for the quick turn around on this issue. It was a major pain-point for our team recently. Very appreciated!
Comment #54
ressa CreditAttribution: ressa at Ardea commentedI just encountered this importing configuration into an existing Drupal 9.2.6 site, which enabled a module and its configuration. I got this error after running
drush config:import
:#3247659: Can't import configuration
If I cleared cache in advance, the import went through smoothly:
Comment #55
BramDriesen@ressa Maybe open a new issue and link back to this one? :-)
Comment #56
ressa CreditAttribution: ressa at Ardea commentedThat's a great idea @BramDriesen! I have created #3247786: Configuration import with new module fails, unless cache is rebuilt beforehand.