Updating Core to 8.6.11 is breaking devel_breakpoint().

There I am getting the following error:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Twig\Node\Expression\ArrayExpression::addElement() must be an instance of Twig\Node\Expression\AbstractExpression, instance of Twig\Node\CheckToStringNode given

Seems to be a follow up after the changes in core/lib/Drupal/Core/Template/TwigNodeTrans.php

(As a temporary workaround: drupal/twig_xdebug module is only partially working - $argument output is missing)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joville created an issue. See original summary.

pcambra’s picture

Issue summary: View changes
scott_euser’s picture

Title: devel_breakpoint() is broken after core update to 8.6.11 » devel_breakpoint() and kint() are broken after core update to 8.6.11
Issue tags: +Kint

I can also reproduce this with the following code using kint, wondering if we should expand the title as likely the same underlying issue:

{% set some_var = {
  'test'   : 'Testing',
  'test2' : 'Test 2',
} %}

{# Works #}
{{ dump(some_var) }}

{# Causes 'instance of Twig\Node\Expression\AbstractExpression, instance of Twig\Node\CheckToStringNode given' #}
{{ kint(some_var) }}

Drop this in `node.html.twig` for instance.

Same issue occurs in 8.6.12

ErwanMaire’s picture

Same issue for me after a migration from 8.6.10 to 8.6.12

kalmanos’s picture

has anyone found a fix or a workaround or vardumper() till the end of time? :D

heyehren’s picture

Same issue here after update from 8.6.5 to 8.6.12.

ErwanMaire’s picture

Issue tags: +8.6.11 update, +8.6.12 update
joville’s picture

Issue summary: View changes
PCate’s picture

Same issue after updating to 8.6.12.

vjkaran’s picture

The same issue after updating to 8.6.12

afeijo’s picture

Same here with 8.6.12
I started to read the twig module code, but its quite complex and many files involved. I doubt I will figure this out :)

scott_euser’s picture

The issue is here in Twig:

In vendor/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php there is:

private function wrapNode(Node $node, $name)
{
    $expr = $node->getNode($name);
    if ($expr instanceof NameExpression || $expr instanceof GetAttrExpression) {
        $node->setNode($name, new CheckToStringNode($expr));
    }
}

Both NameExpression and GetAttrExpression extend AbstractExpression.
CheckToStringNode does not extend AbstractExpression.

A solution would be to update Twig like so (which solves the problem):

diff --git a/src/Node/Node.php b/src/Node/Node.php
index d60367ff..79325e06 100644
--- a/src/Node/Node.php
+++ b/src/Node/Node.php
@@ -13,13 +13,14 @@
 namespace Twig\Node;
 
 use Twig\Compiler;
+use Twig\Node\Node\AbstractExpression;
 
 /**
  * Represents a node in the AST.
  *
  * @author Fabien Potencier <fabien@symfony.com>
  */
-class Node implements \Twig_NodeInterface
+class Node extends AbstractExpression implements \Twig_NodeInterface
 {
     protected $nodes;
     protected $attributes;

I am not confident that this is a Twig is or whether it is our Drupal implementation of Twig.

scott_euser’s picture

I have created an issue in github for Twig, hoping someone can shed some light whether patching Twig is the solution or whether this is our implementation of Twig in Drupal.

Github issue:
https://github.com/twigphp/Twig/issues/2908

afeijo’s picture

Your suggested change didn't work for me, there is no Twig\Node\Node\AbstractExpression

but there is Twig\Node\Expression\AbstractExpression

With that, another error pops up:

Error: Class 'Twig\Node\Node' not found in include() (line 22 of twig/twig/src/Node/Expression/AbstractExpression.php).

ryrye’s picture

Issue tags: +8.6.13 update

This is still broken in D8.6.13

scott_euser’s picture

Status: Active » Fixed

Fix now committed to Twig itself:
https://github.com/twigphp/Twig/issues/2908

On next release of Twig, composer update will fix this.

carsonw’s picture

The next release of Twig is now ready: https://github.com/twigphp/Twig/releases/tag/v2.7.4

moshe weitzman’s picture

Nice work. I'd consider a patch which adds a conflict statement to our composer.json so we discourage use of bad twig versions.

Spokje’s picture

Spokje’s picture

Hmm, this is beyond my Testbot knowledge level.

As a workaround:

For me {{ kint(some_var) }} in the example at #3 works after I've did a composer update twig/twig which got package `twig/twig` up to version 1.38.4

SushiKong’s picture

I used just {{ kint() }} works fine.

moshe weitzman’s picture

Title: devel_breakpoint() and kint() are broken after core update to 8.6.11 » devel_breakpoint() and kint() are broken with twig/twig < 1.28.4
Priority: Normal » Major
Status: Fixed » Active

Someone needs to make an issue to update twig in drupal core. until then, this issue remains a problem and is breaking devel's automated tests.

moshe weitzman’s picture

Title: devel_breakpoint() and kint() are broken with twig/twig < 1.28.4 » devel_breakpoint() and kint() are broken with twig/twig < 1.38.4
scott_euser’s picture

With "twig/twig": "^1.38.2", doesn't it allow 1.38.4 given the ^?
https://cgit.drupalcode.org/drupal/tree/core/composer.json?h=8.6.x#n35

Spokje’s picture

@scott_euser Not in Testbot-land by the looks of it, haven't got around to test it in a real-live scenario.
But since Testbot doesn't allow 1.38.4, the tests for this module will still be broken, so the patch won't help with that.

mikelutz’s picture

Someone needs to make an issue to update twig in drupal core. until then, this issue remains a problem and is breaking devel's automated tests.

But since Testbot doesn't allow 1.38.4, the tests for this module will still be broken, so the patch won't help with that.

For the record, Testbot does what WE tell it to do, not what core tells it to do... :-p

Spokje’s picture

@mikelutz: You, kind Sir, are a gentleman and a scholar.
Nifty trick!

moshe weitzman’s picture

Status: Needs review » Needs work

OK, that gets our tests to green. But it doesn't help real users who face this error.

The documented way to install Drupal now is to use drupal-project and that requires webflo/drupal-core-require-dev. That project forces folks to use 1.38.2, and thats why I suggested that the only way to fix this issue for users to is to upgrade twig in core.

moshe weitzman’s picture

I merged latest patch to get our tests green. Keeping this open for better visibility.

wrg20’s picture

+1 following

vacho’s picture

Hi!!

Why you use www-data user?
Not all SO use this for Apache, and not all use apache.

+          - "cd ${SOURCE_DIR} && sudo -u www-data composer require drush/drush:^9.6.1 && sudo -u www-data composer update twig/twig"
moshe weitzman’s picture

Status: Needs work » Closed (outdated)

Core now requires Twig 1.42.3.

jonathan1055’s picture

For reference, the twig update has now been removed from the 8.x-3.x branch

https://www.drupal.org/commitlog/commit/42/9115de50de1920914ef5c6206d8ee...