Problem/Motivation
There is an issue with Twig 1.38.2 (introduced in #3039408: Updating twig/twig to v1.38.0 or v1.38.1 causes fatal error), when using {% embed %}
tags in your template:
https://github.com/twigphp/Twig/issues/2898
Please also follow that upstream issue to get updates/clarifications for it, but so far it seems that a code change in Twig has lead to this error, due to the way Drupal handles template caching.
The Exception
Twig\Error\RuntimeError: Failed to load Twig template "path/to/user.html.twig", index "1128131273": cache might be corrupted. in Twig\Environment->loadClass() (line 14 of path/to/user.html.twig).
Proposed resolution
Wait for a potential fix in the upstream issue and update Drupal's composer.json to use the new Twig version.
Fix Drupal template caching code to reflect changes made in Twig package.
Remaining tasks
Provide a patch that targets a new working Twig releaseProvide a patch- Provide tests for current patch
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#50 | interdiff-3040210-39-49FAIL.txt | 1.44 KB | phenaproxima |
#49 | 3040210-PASS.patch | 4.79 KB | phenaproxima |
#49 | 3040210-FAIL.patch | 3.95 KB | phenaproxima |
#43 | 3040210-42.patch | 859 bytes | lauriii |
#39 | interdiff_10-39.txt | 2.91 KB | shaal |
Comments
Comment #2
hctomComment #3
hctomComment #4
hctomComment #5
hctomLast typo fixes... I hope ;)
Comment #6
hctomBy the way: This issue does not occure with Drupal core themes themselves, because they do not use
{% embed %}
Twig tags.Comment #7
SpokjeSeems to be solvable in Drupal itself.
The newly introduced '___' in Twig (https://github.com/twigphp/Twig/commit/4eeaf763a2954c2dfbf73fa0194926df9...) doesn't seem to play along nice with the template caching.
Needs tests and more eyes on it, but this patch works for me, let's give it a whirl...
Comment #8
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedRe-rolling the patch. The patch could be applied to 8.6.11.
Comment #9
eelkeblokWe just came to the same conclusion. It looks like this is actually an interaction between some code in Drupal that relies on internal naming within Twig. The linked Twig issue shows that Twig's naming of the internally created template classes has changed to using a triple underscore where it used to use a single underscore, presumably because some checks for its presence were triggering false positives. Drupal itself does something similar in TwigEnvironment, where it amends this behaviour with some of its own. Because of the name mismatch, things go awry.
Comment #10
SpokjeRight, that'll teach me not to create a patch against the non git-version of Drupal core...
Correct patch format now (Famous Last Words...)
EDIT: Sorry @a.dmitriiev, we seem to have cross-posted there. Your patch is indeed the correct version of my initial patch as well as my patch #10 is.
Comment #11
SpokjeComment #12
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedNo problem, Spokje, I just wanted to make my installation working and was not patient to wait, thanks for initial patch.
Comment #13
Spokje@a.dmitriiev Did it work for you?
Comment #14
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedI might be missing something, but the patch doesn't work for me :( I am using particle theme from phase2
Comment #15
SpokjeHmm, we're on a custom patternlab implementation theme and for us it seems to work so far.
(It all seemed as a too easy fix anyway...)
Comment #16
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedWe also use components module (https://www.drupal.org/project/components) to place the templates not in theme folder.
Comment #17
eelkeblokIt does work for us.
We too are using the Components module (there is probably going to be a lot of overlap with this issue, as it looks to be specific to Twig embeds, and embeds will be much more common if you use the Components module to move your style guide templates to a different location).
Comment #18
SpokjeWe're using "drupal/components": "1.0"
Comment #19
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedSorry, I was wrong, I tried on clean installation and on different environment and now can confirm that it works.
Thank you very much.
P.S. I was also stupid enough to miscount the number of underscores in my patch ......
Again, thank you
Comment #20
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedComment #21
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedIncreasing the priority to Critical, because sites with the themes that use embed are at the moment broken completely.
Comment #22
SpokjePatch #10 seems to at least not break any of the existing tests.
Currently working on a test for this patch.
Comment #23
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedComment #24
vijaycs85Can we provide some test to prove the current issue and fix please?
Comment #25
hctomJust updating the issue summary with the new information
Comment #26
xjmYeah, NW for tests, thanks everyone! It'd also be good to report this break upstream in Twig because a minor version update shouldn't have broken this either.
Comment #27
SpokjeWorking on Test ATM, upstream was reported (in fact it was where all the "fun" started), link to that issue is in the summary.
And Yay for non-breaking stuff in minor version updates...
EDIT: I'm not a Drupal PHPUnit test guru, so if anybody wants to beat me to it, go for it! :)
Comment #28
eelkeblokThe question is whether we should be relying on the naming being in sync. It basically comes down to whether that is part of the "published API", I guess.
Guessing the status update was a mistake.
Comment #29
cilefen CreditAttribution: cilefen at Institute for Advanced Study commented@xjm: https://github.com/twigphp/Twig/issues/2898
Comment #30
Spokje@eelkeblok
> Guessing the status update was a mistake.
Indeed, thanks for fixing that
Comment #31
crash_springfield CreditAttribution: crash_springfield commentedThe patch isn't fixing the errors I'm getting on specific admin routes
Comment #32
wells@crash_springfield - have you updated to Drupal core 8.6.11 and looked at #3039408: Updating twig/twig to v1.38.0 or v1.38.1 causes fatal error? I had issues on admin routes that the patch there fixed and it is now in 8.6.11. I think this issue only affects themes using the
embed
function.Comment #33
SpokjeSo....
Getting core tests to execute is a _lot_ harder than expected, lack of documentation for dummies like me isn't really helping.
This is what I can come up with, can't seem to get it tested locally so I'll just upload it here and let someone with a bigger brain create a real test.
I will look into PHPUnit testing on Core more, but since this is an urgent issue, I'm happy to hand this over for now.
Basically the only thing that needs testing is:
- A Twig template with a
{% embed '/something/somewhere' %} ... {% endembed %}
breaks Drupal. Even when there's nothing on the ...- With patch #10 the breakage shouldn't happen.
Comment #34
SpokjeComment #35
SpokjeComment #36
xjmHey @Spokje, thanks for taking a shot at it! I think you're on a good track (adding a fixture template and then testing it), but it looks like your patch has some merge conflicts or such in the diff in it and so it won't apply to be tested.
Comment #37
crash_springfield CreditAttribution: crash_springfield commented@wells yeah it was updating 8.6.11 that caused the error
Comment #38
wells@crash_springfield, can you post the specific errors you are getting and on what routes? If it's the same exception as the ones in this issue description, it may also be useful to see the relevant twig template contents.
Comment #39
shaalMade a quick fix for #33 by @Spokje, so the patch can be tested and applied.
Comment #40
crash_springfield CreditAttribution: crash_springfield commented@wells here's what I had in my issue that has since been closed as a duplicate:
"/admin/modules/update" and "/admin/modules/install" both work, but "/admin/modules/uninstall" gives the error:
Twig\Error\SyntaxError: An exception has been thrown during the compilation of a template ("Attribute "name" does not exist for Node "Twig\Node\CheckToStringNode".") in "core/themes/stable
"/admin/reports/dblog" gives:
Twig\Error\SyntaxError: An exception has been thrown during the compilation of a template ("Attribute "name" does not exist for Node "Twig\Node\CheckToStringNode".") in "core/themes/classy
"/admin/reports/updates" gives:
Twig\Error\SyntaxError: An exception has been thrown during the compilation of a template("Attribute "name" does not exist for Node "Twig\Node\CheckToStringNode".") in "core/themes/stable
There may be more, but that's all I've come across so far.
Comment #41
SpokjeThanks @shaal for correcting my mad mistakes :)
Comment #42
Spokje@crash_springfield What theme are you using for Administration theme (Bottom of
/admin/appearance
)?Comment #43
lauriiiThis problem only exists in 8.5.x and 8.6.x because #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1 changed the way template classes are being generated. We should work on a test coverage to ensure that is the case. Here's a patch that uses the fix from #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1 which I think we should apply here as well.
Comment #44
crash_springfield CreditAttribution: crash_springfield commented@spokje I'm using Adminimal
Comment #45
xjmThanks @crash_springfield and @Spokje -- that does sound like the issue that #3039408: Updating twig/twig to v1.38.0 or v1.38.1 causes fatal error was supposed to have fixed. Could you open a separate bug report to discuss that issue? (Also be sure you've cleared your site cache.)
Comment #46
VladimirAusThanks @Spokje and @shaal.
@crash_springfield: checked my theme: all paths you mentioned are working fine on seven.
Comment #47
VladimirAusAlso checked paths in
Adminimal 8.x-1.4
. All working for me.Comment #48
mikemadison CreditAttribution: mikemadison at Acquia commentedThe patch in #43 applies cleanly and immediately solves the error for me. Working on a PR now to incorporate.
Comment #49
phenaproximaOK -- @lauriii walked me through writing a fail patch (i.e., a test). Here ya go!
Comment #50
phenaproximaHere's an interdiff between #39 and the fail patch in #49.
Comment #51
pdenooijer CreditAttribution: pdenooijer at Ordina Digital Services for RTL Nieuws commentedI think we should include to change to `Twig\Environment` in the patch as well, as that is the new class. The other one is deprecated in 2.7 of twig/twig.
Comment #52
lauriiiWe pair coded the test coverage for #49 and I think it should be ready to go. On top of the automated test coverage, I've tested manually that this fixes the problem.
Comment #53
SpokjeThanks @phenaproxima @lauriii (and Acquia) for taking over and especially for the interdiff in #50. Now I see why my test didn't run.
Comment #54
xjmRegarding #51, I think that's out of scope here.
Thanks everyone!
Comment #55
cilefen CreditAttribution: cilefen at Institute for Advanced Study commented@pdenooijer Please open an issue for that, if one does not already exist.
Comment #57
pdenooijer CreditAttribution: pdenooijer at Ordina Digital Services for RTL Nieuws commentedYeah that's true, I thought as a bit of boy scouting while we are at it.
Anyway the patch works as my Behat test that where failing are all green now so RTBC +1.
Comment #62
xjmAlright, committed the tests to 8.8.x and 8.7.x, and the full patch to 8.6.x and 8.5.x. Thanks everyone for helping fix this issue quickly! We'll create (yet more...) hotfix releases later today to fix this for themes that were broken by it.
Comment #63
hctomThanks everyone for all the hard work and fixing this issue that quickly!
Comment #64
jeromewiley CreditAttribution: jeromewiley commentedIs the information in comment #49 what fixes this?
I need to fix this in order to apply the 8.6.10 --> 8.6.13 security patch.
Please advise step by step instructions on how to apply this (and will this fix be wiped away with the next theme/core/module update?)
Thanks!
Comment #65
cilefen CreditAttribution: cilefen at Institute for Advanced Study commented@jeromewiley This was released in 8.6.12. Are you somehow unable to upgrade to 8.6.13 without this applied as a patch?
Comment #66
jeromewiley CreditAttribution: jeromewiley commented@cilefen I posted some information in the Drupal slack channel #support (didn't want to add irrelevant thread here) - hope that is ok