Problem/Motivation

graphql_twig 8.x-1.0-beta16 with Drupal 8.9.10 produces an error on every page load:

Error: Call to undefined method __TwigTemplate_42534f1e1642e4f45ede9e87932f74e08e0f950a474ccaeafc9b35c41562920a::checkSecurity() in __TwigTemplate_42534f1e1642e4f45ede9e87932f74e08e0f950a474ccaeafc9b35c41562920a->__construct() (line 26 of /app/web/sites/default/files/php/twig/5fc77cd82c09f_views-view.html.twig_LoLin7Z3SA3xJTRywYMb0e8ud/2_I3lCViozvQ-LdG-AJJ8MQ24-n150Txp7lqufKb1pQ.php)

#0 /app/vendor/twig/twig/src/Environment.php(510): __TwigTemplate_42534f1e1642e4f45ede9e87932f74e08e0f950a474ccaeafc9b35c41562920a->__construct(Object(Drupal\graphql_twig\GraphQLTwigEnvironment))
#1 /app/vendor/twig/twig/src/Environment.php(445): Twig\Environment->loadClass('__TwigTemplate_...', 'core/themes/bar...', NULL)
#2 /app/web/core/themes/engines/twig/twig.engine(64): Twig\Environment->loadTemplate('core/themes/bar...')
#3 /app/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('core/themes/bar...', Array)
#4 /app/web/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render('views_view', Array)
#5 /app/web/core/lib/Drupal/Core/Render/Renderer.php(444): Drupal\Core\Render\Renderer->doRender(Array)
#6 /app/web/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender(Array, false)
#7 /app/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(226): Drupal\Core\Render\Renderer->render(Array, false)
#8 /app/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#9 /app/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(227): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#10 /app/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#11 /app/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))
#12 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#13 /app/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#14 /app/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent))
#15 /app/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#16 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /app/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#25 {main}

.

Steps to reproduce

Use a vanilla Drupal 8 installation and add latest graphql_twig:

composer require drupal/graphql_twig
drush en graphql_twig -y

Visit any page in the frontend or admin theme.

Error does not occur if with a vanilla Drupal9 installation.

CommentFileSizeAuthor
#9 graphql_twig-3186005-9.patch772 bytesolli

Comments

drupov created an issue. See original summary.

Belialius’s picture

Can confirm that I have the same issue on Drupal 8.9.10

gaards’s picture

Haven't seen that error on our current site (Drupal 8.9.11), but maybe the error could be attributed to differences between themes or module usage between sites (Twig version should be the same, 1.42.5)? However we're seeing a similar error when trying to upgrade a site from Drupal 8.9 to Drupal 9.1, so there's definitely something that's not working okay (Twig version is updated to 2.14.1).

Here are some pointers that maybe could shed some light into this issue:
https://github.com/twigphp/Twig/issues/3411
https://github.com/twigphp/Twig/pull/3413

Error: Call to undefined method __TwigTemplate_ebb25357d018afcd2192ed623e511c2daff2ad49a876a9b564442bd17ef5244f::checkSecurity() in __TwigTemplate_ebb25357d018afcd2192ed623e511c2daff2ad49a876a9b564442bd17ef5244f->__construct() (line 32 of /var/www/html/vendor/twig/twig/src/Environment.php(418) : eval()'d code).
__TwigTemplate_ebb25357d018afcd2192ed623e511c2daff2ad49a876a9b564442bd17ef5244f->__construct(Object) (Line: 430)
Twig\Environment->loadClass('__TwigTemplate_ebb25357d018afcd2192ed623e511c2daff2ad49a876a9b564442bd17ef5244f', 'core/themes/stable/templates/field/field--node--title.html.twig', NULL) (Line: 381)
Twig\Environment->loadTemplate('core/themes/stable/templates/field/field--node--title.html.twig') (Line: 65)
twig_render_template('core/themes/stable/templates/field/field--node--title.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('field', Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 74)
Drupal\Core\Entity\Controller\EntityViewController->buildTitle(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
drupov’s picture

In the mentioned vanilla Drupal installation the twig version is (according to vendor/twig/twig/CHANGELOG)

# 1.44.1 (2020-10-27)

 * Fix "include(template_from_string())"

Drupal has been installed via composer, so with composer create-project drupal-composer/drupal-project:8.x-dev drupal8 --stability dev --no-interaction

PHP version is 7.3.25.

I haven't tried downgrading Twig to 1.42.5 yet, will post my finding on that later.

One last thing: I am using a very basic Lando recipe, but I don't think that is related.

gaards’s picture

Interesting, I would have expected it to stay at 1.42.5 as it is restricted to that version in the official Drupal repo: https://git.drupalcode.org/project/drupal/-/blob/8.9.x/composer.lock#L3926

It looks like that project/command allows Twig to be updated to the very latest version, while projects using the recommended package (drupal/recommended-project) limits Twig to 1.42.5. This is how a Drupal project with the recommended package is installed according to the documentation:
https://www.drupal.org/docs/develop/using-composer/using-composer-to-ins...

But we could be on to something, meaning the probable cause is a Twig update that has made it so that the current code in this module is incompatible (this would explain the problems with Drupal 9 upgrade we had with latest Twig 2, and you had with the latest version of Twig 1). The issue links I posted above seem to be very much relevant, but I'm still unsure what needs to change in this module to make it compatible.

gaards’s picture

I had another look at this on a fresh D9.1 site. I tried replacing all deprecated Twig classes in the module but the error is still present. I then tried to identify which part of the code causes the WSOD and found that commenting out the following line would remove the WSOD (but I expect this to break the module functionality):

https://git.drupalcode.org/project/graphql_twig/-/blob/8.x-1.x/src/Graph...

jellyburger’s picture

I have the same problem with Drupal 8.9.12.

Has anyone figured out a solution?

el1_1el’s picture

Ive been struggling to update from 8.9.10 to 8.9.13 with and older composer.json using drupal/drupal. Ive tried various versions of twig and it seems this module became incompatible between twig versions 1.43.1 and 1.44.0. 1.44.1 was supposed to be the fix - https://github.com/twigphp/Twig/issues/3411 - however it did not work for me with this module.

If you need an immediate solution composer require twig/twig:1.43.1 seems to work, however it could bite you next time you do a composer update. It looks like maybe adding the sandbox extension (https://github.com/twigphp/Twig/issues/3411#issuecomment-714281764) or changing the twig (https://github.com/twigphp/Twig/issues/3411#issuecomment-713677851) might work but I dont see where the error occurs from this module, just can see that turning it off fixes the issue.

olli’s picture

Status: Active » Needs review
StatusFileSize
new772 bytes

Here's a patch that seems to add back the missing checkSecurity method on drupal 9.1.4.

drupov’s picture

Super! #9 Works for me! Thanks

el1_1el’s picture

Status: Needs review » Reviewed & tested by the community

#9 working for me also. Thanks!

3li’s picture

#9 has worked for me.

  • saschaeggi committed 25322fa on 8.x-1.x authored by olli
    Issue #3186005 by olli: Error: Call to undefined method __TwigTemplate_...
saschaeggi’s picture

Status: Reviewed & tested by the community » Fixed

Thanks y'all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.