Short summary of what's going on
When people do not take care of the consistency of their cache contexts, incomplete or wildly different cache redirects may be attempted to be written. At best these lead to uncacheable items, at worst they lead to security issues. This is why D10.4 and D11 shipped with new hardening that throws an E_USER_WARNING when something wrong is detected.
This makes tests fail if the module has insecure code, which is what we want. But the message being shown could be more informative, so the MR in this issue adds the cache ID of the entry where the flaw is detected.
Original report
i have cache problem after i updated to 10.4.0
always getting this message :
User warning: Trying to overwrite a cache redirect with one that has nothing in common, old one at address "languages:language_interface, theme, user.permissions" was pointing to "url", new one points to "url.path.parent, url.path.is_front, route". in Drupal\Core\Cache\VariationCache->set() (line 143 of core/lib/Drupal/Core/Cache/VariationCache.php)
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | 3495165-core-fix-warning-issue-35.patch | 570 bytes | _renify_ |
Issue fork drupal-3495165
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:
Comments
Comment #2
cilefen commentedI don't understand this bug report very well as written. Is it possibly something to do with #3494938: Individual admin pages no longer accessible after update to 10.4?
Comment #3
adrianm6254 commentedI am having the same issue. I have not noticed any other issues except the Warning in my error log.
My system is:
php 8.3.14
Apache 2.4.62
MySQL 8.0.40
I am including what is posted in my error log.
User warning: Trying to overwrite a cache redirect with one that has nothing in common, old one at address "languages:language_interface, theme, user.permissions, route.name.is_layout_builder_ui" was pointing to "context_stack:view:9449f4ef8e50a89825a4445c64e93b4a", new one points to "context_stack:view:ee1d86660efff497e0d4f88f265e687e". in Drupal\Core\Cache\VariationCache->set() (line 138 of .../web/core/lib/Drupal/Core/Cache/VariationCache.php)
#0 .../web/core/includes/bootstrap.inc(166): _drupal_error_handler_real(512, 'Trying to overw...', '/home/xxx...', 138)
#1 [internal function]: _drupal_error_handler(512, 'Trying to overw...', '/home/xxx...', 138)
#2 .../web/core/lib/Drupal/Core/Cache/VariationCache.php(138): trigger_error('Trying to overw...', 512)
#3 .../web/core/lib/Drupal/Core/Render/RenderCache.php(92): Drupal\Core\Cache\VariationCache->set(Array, Array, Object(Drupal\Core\Cache\CacheableMetadata), Object(Drupal\Core\Cache\CacheableMetadata))
#4 .../web/core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php(127): Drupal\Core\Render\RenderCache->set(Array, Array)
#5 .../web/core/lib/Drupal/Core/Render/Renderer.php(584): Drupal\Core\Render\PlaceholderingRenderCache->set(Array, Array)
#6 .../web/core/lib/Drupal/Core/Render/Renderer.php(504): Drupal\Core\Render\Renderer->doRender(Array)
#7 .../web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#8 .../web/core/lib/Drupal/Core/Template/TwigExtension.php(484): Drupal\Core\Render\Renderer->render(Array)
#9 .../web/sites/default/files/php/twig/6765f41a5db7e_page.html.twig_vgqHdACnoXdk7NRozFtijxvjO/LvotwseHwWQoOqxChHzF_p4uRLXDE_IdFmPB06YFbLY.php(329): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#10 .../vendor/twig/twig/src/Template.php(387): __TwigTemplate_480925317b68064ddd31e111b10d8f9c->doDisplay(Array, Array)
#11 .../vendor/twig/twig/src/Template.php(343): Twig\Template->yield(Array, Array)
#12 .../vendor/twig/twig/src/Template.php(358): Twig\Template->display(Array)
#13 .../vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render(Array)
#14 .../web/core/themes/engines/twig/twig.engine(33): Twig\TemplateWrapper->render(Array)
#15 .../web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('themes/custom/n...', Array)
#16 .../web/core/lib/Drupal/Core/Render/Renderer.php(491): Drupal\Core\Theme\ThemeManager->render('page', Array)
#17 .../web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#18 .../web/core/lib/Drupal/Core/Template/TwigExtension.php(484): Drupal\Core\Render\Renderer->render(Array)
#19 .../web/sites/default/files/php/twig/6765f41a5db7e_html.html.twig_O2cP37t0XjrjP--x4EKWg3wIm/-Y1_TmydklAhduRCKolylSEwdglGn2phDpZH-fgNzig.php(79): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#20 .../vendor/twig/twig/src/Template.php(387): __TwigTemplate_cc8cca55ec5f9b87f8c4ee0fae94bf67->doDisplay(Array, Array)
#21 .../vendor/twig/twig/src/Template.php(343): Twig\Template->yield(Array, Array)
#22 .../vendor/twig/twig/src/Template.php(358): Twig\Template->display(Array)
#23 .../vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render(Array)
#24 .../web/core/themes/engines/twig/twig.engine(33): Twig\TemplateWrapper->render(Array)
#25 .../web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('themes/custom/n...', Array)
#26 .../web/core/lib/Drupal/Core/Render/Renderer.php(491): Drupal\Core\Theme\ThemeManager->render('html', Array)
#27 .../web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#28 .../web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(158): Drupal\Core\Render\Renderer->render(Array)
#29 .../web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#30 .../web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(153): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#31 .../web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#32 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#33 .../web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#34 .../vendor/symfony/http-kernel/HttpKernel.php(186): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#35 .../vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#36 .../web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 .../web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 .../web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 .../web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#40 .../web/core/modules/page_cache/src/StackMiddleware/PageCache.php(201): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#41 .../web/core/modules/page_cache/src/StackMiddleware/PageCache.php(138): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#42 .../web/core/modules/page_cache/src/StackMiddleware/PageCache.php(87): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#43 .../web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#44 .../web/modules/contrib/crowdsec/src/Middleware.php(96): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#45 .../web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\crowdsec\Middleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#46 .../web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#47 .../web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#48 .../web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#49 .../web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#50 .../web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#51 {main}
Comment #4
catchYour backtrace shows a cache key with context_stack, which looks like it's from https://www.drupal.org/project/context_stack which has a large notice on its homepage recommending to uninstall it.
Can you try uninstalling that module and see if the problem persists?
Comment #5
glottus commentedI'm seeing similar, but do not have the context_stack module.
User warning: Trying to overwrite a cache redirect with one that has nothing in common, old one at address "languages:language_interface, theme, user.permissions" was pointing to "url.path.parent, url.path.is_front, route", new one points to "url.path". in Drupal\Core\Cache\VariationCache->set() (line 138 of core/lib/Drupal/Core/Cache/VariationCache.php).
Drupal\Core\Cache\VariationCache->set() (Line: 92)
Drupal\Core\Render\RenderCache->set() (Line: 127)
Drupal\Core\Render\PlaceholderingRenderCache->set() (Line: 584)
Drupal\Core\Render\Renderer->doRender() (Line: 504)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 135)
__TwigTemplate_7933b1592f1978df929103e8f2b9cd6d->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 98)
__TwigTemplate_036e62bb102d1f6e378f9094f7809ad1->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Comment #6
texas-bronius commentedAlso hoping to track this one down. The author of #3452181: VariationCache needs to be more defensive about cache context manipulation to avoid broken redirects says:
So looks like it's come to fruition? Thanks for the tip above about finding the potentially offending module's name in the stack. Will update if I figure something out :)
Comment #7
ressaI am also seeing this:
... randomly in a fresh Drupal 10.4 install for CiviCRM.
Comment #8
catchI think there are one or two possible bugs in the logic triggering the warning.
From @ressa's example:
I think we might need to do something with CacheContextsManager::optimizeTokens() here for the situation where we're comparing url vs. url.query_args. Not sure exactly how it would work though, something like optimize both contexts, then merge the contexts, then optimize the result of that and compare before/after the final optimization and if there's a difference, don't trigger the warning.
Comment #9
catchAny fixes will need to happen on the 11.x branch and be backported.
Comment #11
catchPut up an MR that removes the exception altogether.
We'll need a follow-up to add it back with some or all of the logic in #8, I also think it needs to be a trigger_error() until 12.x rather than an exception. Critical because this is user facing. I'm pretty sure #3 is an example of the exception working as it should though.
Comment #12
catchComment #13
berdirtoken tests did also run into a pretty weird version of this that caused test fails, but only tests are affected there: #3495530: Fixing test fails on 11.1
Comment #14
catchWait a minute no-one's triggering the exception here, only the warning, so my MR is useless.
Comment #15
catchUpdate the MR so it just adds the cache ID to the warning message, this will give us a better idea of what's going on.
Reading the comment here, I think I might also be wrong about CacheContextsManager::optimize() since the comment explicitly says this:
So let's get some more information about where this is happening - it may well be that this showing actual bugs everywhere, in which case the cache keys should help to show where from.
Comment #16
catchLet's just improve the error message here, then open a follow-up to track cases of this that come up.
Comment #17
smustgrave commentedWonder if steps and issue summary update could still happen please.
Comment #18
superrn commentedTesting 10.4.0 causes the same issue for us, and several projects currently on 10.3.x are impacted. Reverting to 10.3.10 resolves it. We can not proceed with the 10.4 upgrade until this is fixed.
How can we help with troubleshooting?
Comment #19
eiriksmProbably more people like myself, but I had custom code that had to be adjusted much like in book.module:
https://git.drupalcode.org/project/book/-/merge_requests/15/diffs
Hope that helps
Comment #20
berdirYes, the most common one for this are breadcrumb builders, happened in a number of projects.
I'm also not sure that throwing an exception is a good idea, but:
> We can not proceed with the 10.4 upgrade until this is fixed.
I assume you hit the exception, not the warning. This won't be "fixed". At best it will change the exception to an error or warning. The reason an exception was chosen is that current breadcrumb builders result in cache bugs. But I agree that an exception is too strong for that in a minor update, it should be a deprecation or maybe warning/error that gets logged but doesn't break the site.
> How can we help with troubleshooting?
If you get the warning, try the patch to get a better warning message that should help you identify what thing is unhappy.
If you get the exception, the best way forward is to fix it now, look for breadcrumb builders in contrib or custom projects, if none then you'll need to figure out what else is triggering this.
Comment #21
texas-bronius commentedWith the "add cid" patch in #15 I see the erroneous cid in my case is
entity_view:block:****_breadcrumbs:[languages:language_interface]=en:[theme]=*****:[user.permissions]=is-admin. I updated the menu_breadcrumbs to latest 2.0.x-dev, and the message appears to have gone away. If I get to narrow down which of the latest dev commits actually fixed it, I'll update this comment.Comment #22
superrn commentedIn our case, the menu_breadcrumb was also involved. Thank you texas-bronious!.
In addition to deploying the latest 2.0.x-dev, I had to apply this patch too: https://www.drupal.org/project/menu_breadcrumb/issues/3495164
Then the issue was resolved.
I hope this helps someone out there.
Comment #23
kristiaanvandeneyndeAs previously pointed out by others, breadcrumbs were a big offender in core and contrib and the linked fix for the Book module shows exactly how to alleviate the issue.
On how to improve the message: I actually had the CID in there before but chose to remove that to keep the message shorter. I am not at all opposed to adding back the CID as I agree it can help debugging.
MR is RTBC for me, will update IS a bit. Keep in mind the goal is to turn the E_USER_WARNING into an exception in future major versions of Drupal. Once #1537198: Add a Production/Development toggle lands, we can already convert the warning into an exception for dev sites.
Comment #24
alexpottCommitted and pushed 25b6571b63e to 11.x and c19f0d7139e to 11.1.x and ea9093d961d to 10.5.x and 0e3d2d669de to 10.4.x. Thanks!
Comment #25
alexpottComment #30
alexpottComment #31
ressaThanks this patch is great, and you get actually useful hints to the culprit now. Again, it was breadcrumb-related:
EDIT: The cause was missing route cachability metadata in civicrm/src/CivicrmBreadcrumbBuilder.php
I created #3498576: Missing route cachability metadata in Claro.
Comment #32
ressaAdding a related issue, which contains a solution.
Comment #33
catchReally nice to see that this is uncovering and helping to fix bugs a lot faster, thanks for following up with the links!
Comment #35
_renify_ commented