Problem/Motivation
Follow-up from #3256973: When trying to install ECA or Context Stack alone a fatal error takes place "Method Drupal\context_stack\ContextStackTrait::__sleep() cannot take arguments"
On a not yet identified circumstance, Context Stack runs into an error when trying to uninstall it via extension UI:
The website encountered an unexpected error. Please try again later.
AssertionError: Failed to assert that "context_stack:account:5dc9b6442bc7569777ce3c3da63d8a11" are valid cache contexts. in assert() (line 31 of core/lib/Drupal/Core/Cache/Cache.php).
assert(, 'Failed to assert that "context_stack:account:5dc9b6442bc7569777ce3c3da63d8a11" are valid cache contexts.') (Line: 31)
Drupal\Core\Cache\Cache::mergeContexts(Array, Array) (Line: 33)
Drupal\Core\Cache\CacheableMetadata->addCacheContexts(Array) (Line: 69)
Drupal\context_stack\ContextCollection->getCacheContexts() (Line: 171)
Drupal\Core\Cache\CacheableMetadata::createFromObject(Object) (Line: 129)
Drupal\context_stack\ContextStack->pop() (Line: 103)
Drupal\context_stack\EventSubscriber\ContextStackControllerWrapperSubscriber->onKernelRequestFinish(Object, 'kernel.finish_request', Object)
call_user_func(Array, Object, 'kernel.finish_request', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.finish_request') (Line: 207)
Symfony\Component\HttpKernel\HttpKernel->finishRequest(Object, 1) (Line: 193)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 245)
Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object, Object, 1) (Line: 91)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
Proposed resolution
Remaining tasks
We need to clarify:
Some factors that might lead to our different obersvations:
- Used PHP version - is the error also showing up using PHP 7.4, or only when using PHP8?
- Other installed modules that are not by default installed when using the standard installation profile. If you have a bunch of modules installed, feel free to share your list of installed modules (resided within exported core.extension.yml).
User interface changes
API changes
Data model changes
Comments
Comment #2
mxh commentedComment #3
rkollerabout your questions:
- the white screens and pasted errors codes where when i was on php 8 (see screenshot 80.png) but i've also changed the env to php 74 (see screenshot 74.png). same error but no white screen as you can see. that i consider noteworthy.
- and the modules enabled != the standard profile in drupal core are:
admin toolbar
admin toolbar extra tools
admin toolbar links access filter
danse config
danse content
danse form
danse log
danse user
danse webhook
drupal audit notification subscription event
advanced queue
token
push framework
push framework email
json:api
restful web services
serialization
the last three are installed because of danse webhook and advanced queue and token also because of one of the danse modules. and did one final test and removed all of those modules (except the three admintoolbar ones - would be highly unlikely that those three might interfere with context stack) and tried to install and uninstall context stack, but same outcome, the error showed up again (tested with php 8 as the environment)
p.s. the error doesnt happen occasionally but consistently on my end no matter which php version (7.4/8) i am using. and is there anything i might be able to debug on my end since you are unable to reproduce the error on your end that consistently or not at all?
Comment #4
mxh commentedOk, so the assertion fails independently from the used PHP version. One factor less to have a look at, which is great.
Appreciating your efforts taken here. If you like, try to see first, whether on a completely fresh Drupal installation using standard installation profile (also not having any further composer required dependencies besides
drupal/context_stack:^1.0@betaand also make sure no patches are applied) still leads to the mentioned error. If not, we need to subsequently identify on which additionally installed module the uninstallation breaks. If yes, we need to look out for another factor that might lead to the problem.Comment #5
rkollerok i've tried several variants. first i've created a fresh install of drupal. i've even passed on installing drush. just the drupal standard profile and the context stack module nothing else (i've only added
$config['system.logging']['error_level'] = 'verbose';to thesettings.phpfile).first i've tried the dev version (had just scanned across the second part of your comment and not really realized you wrote beta instead of dev :( ). that lead to the known error. i've then composer required the beta version and then tried again installing and uninstalling context stack. again the same error got returned. then i had another idea (while still using the beta version). i am using mutagen in ddev (which is basically caching related). so i switched to nfs and tried again after restart to install and uninstall context stack. but again no luck. the same error :(
the only odd thing is that you are unable to reproduce the error with php8. my basic steps for a php8 based server were:
a) composer create "drupal/recommended-project:^9.3.0"
b) $config['system.logging']['error_level'] = 'verbose'; (added to the settings.php file)
c) composer require 'drupal/context_stack:^1.0@beta'
d) performed the site install in the browser (usually i use drush for that)
e) installed context stack in the extend menu
f) uninstalled context stack in the uninstall tab
if it is not reproducible on your end maybe the reason is the local development environment we are using? some difference between ddev and the one you are using and how its web container is set up?
Comment #8
mxh commentedNo problem, it was just testing against the last beta2 release that composer would load. But currently it's not that important, you could also just stick with the latest 1.0.x-dev - that is sometimes not guaranteed though that composer loads the most recent state due to some caching behavior.
Since I'm not able to reproduce the error, it's a poke in the fog. Yet I detected a possible flaw when creating cache contexts, that can lead to the error in some circumstances. For example, when the module is not available anymore on runtime, remaining items that make use of the cache context "context_stack" could then break. I've added some checks so cache contexts would only be added when the according service is available.
Feel free to try it out whether it also covers your error. You'd need to switch (again) to the latest state of 1.0.x-dev for being able to test the additional changes.
Comment #9
mxh commentedAs we have already found out above, this is not a problem regarding the PHP version, since you get the error both on PHP7 and 8 as you posted in #3.
Comment #10
rkollerI've phrased it a bit ambiguous way. I just considered it odd that if we both set up the most minimal installation utilizing php8 like outlined in my list in comment #5, that things are working out for you while i am able to reproduce the error consistently each and every try. I would have expected that you run into the same error and would be able to reproduce.
but good news. i've updated to your latest changes and i have to state you are actually good at "poking into the fog". :D the error is gone on the most basic install. and i've updated to that dev version on the full install as well were i initially ran into the error. it is working there as well now! great! :) setting the issue to rtbc
Comment #11
mxh commentedI tried to reproduce by using the same PHP version, but wasn't able to get that error. And as seen by the screenshot, PHP7 also printed out an error message on your environment.
So it's something else regarding the environment configuration, but I have no clue what it could be. I also uninstalled some PHP extensions like OPCache and X-Debug to see whether this may be a factor, but turned out it wasn't.
Anyway, that's great news that the error is gone now :) thus marking this one as fixed and will tag a new release (1.0.0-beta3), so that you don't need to use the dev-release anymore. Thank you for your fast and helpful feedback.
Comment #12
rkolleryep that was my suspicion i tried to articulate indirectly that the error was caused by different env setup and configuration. but luckily it wasn't necessary to go down that road comparing since you were able to fix things already with your latest commits :)
and yep already moved to beta3. will take a closer look at eca on the weekend. and also thanks again for your quick fixes :)