I keep getting this error when executing cron:

PHP Fatal error:  Call to undefined function twig_template_get_attributes() in sites/default/files/php/twig/590e169237746_sailor-services.html.twig_tx5wK2l_JWei1vWZstowl1eLj/1TcIYQeCkgoVzghW9KT7VKFbwJQRLfrLpzxZLDkP83k.php on line 43
Drush command terminated abnormally due to an unrecoverable error.
Error: Call to undefined function twig_template_get_attributes() in  sites/default/files/php/twig/590e169237746_sailor-services.html.twig_tx5wK2l_JWei1vWZstowl1eLj/1TcIYQeCkgoVzghW9KT7VKFbwJQRLfrLpzxZLDkP83k.php,

Sometimes doing a cache rebuild resolves the problem, other times I have to execute:

rm -rf sites/default/files/php/twig

and then I can execute cron again.

However, now neither work around works. :(

Here is the template for reference:

Proposed resolution

Figure out what's causing the problem. If it's a problem with the twig template, display a more helpful error message.

Remaining tasks

  1. Figure out Problem
  2. Write Patch

User interface changes


API changes


Data model changes



davidwbarratt created an issue. See original summary.

davidwbarratt’s picture

Issue summary: View changes
davidwbarratt’s picture

Issue summary: View changes
davidwbarratt’s picture

Version: 8.4.x-dev » 8.3.x-dev
cilefen’s picture

Priority: Normal » Major

This is major by our definition.

vaplas’s picture

davidwbarratt’s picture

Issue summary: View changes
vaplas’s picture

@davidwbarratt, try to delete the folder sites/default/files/php/twig.

davidwbarratt’s picture

If I try and run `cron` this is what I get:

$ ../vendor/bin/drush cron
PHP Fatal error:  Call to undefined function twig_template_get_attributes() in sites/default/files/php/twig/590e169237746_field.html.twig_GYq9YZZfdUrZslnFXniRNr4_G/e8qpz1xEB9W0UgINsV4Miql5eLUMzUA-AMlOfd4n9fk.php on line 83

If I delete that folder:

$ rm -rf sites/default/files/php/twig

It does fix the issue:

$ ../vendor/bin/drush cron
Cron run successful.

However, if I go edit a piece of content that uses the services template, then I load a different page (like the homepage), then I load the page I edited, I can then run cron again and...

$ ../vendor/bin/drush cron
PHP Fatal error:  Call to undefined function twig_template_get_attributes() in sites/default/files/php/twig/590e169237746_sailor-services.html.twig_tx5wK2l_JWei1vWZstowl1eLj/FQkVZjQXMh1A7xqotCNFytseCpVNRriXh1IkgY2sQvs.php on line 43

so I imagine after cache being cleared, if certain pages are accessed (cached) before others, then this probably doesn't happen, but if the cache clears and other pages are accessed then it blows up cron. The odd this is that it appears that all the pages work correctly (as far as I can tell). The only thing that breaks is cron.

davidwbarratt’s picture

If it helps at all, the code base for the whole site is located here (sans some proprietary scss and javascript):

vaplas’s picture

Maybe /vendor/bin/drush cron uses php 5.6 (where Twig C extension (and hence twig_template_get_attributes) exists). But site uses php 7 (without Twig C extension)?

davidwbarratt’s picture

So... I disabled the Twig C extension and I haven't been able to reproduce the problem since. But then I noticed something odd. The CLI and the web were both using the same version of PHP (5.6), but the latter was using PHP-FPM. I only had the Twig C extension enabled on PHP-FPM (not the CLI). Which means that the web was using it, but cron (on the CLI) was not.

Perhaps this was the problem?

I noticed that it no longer shows up in the Status Report (and isn't even recommended with PHP 7) so I'm fine leaving it disabled if that resolves the issue.

vaplas’s picture

Status: Active » Needs review

#12 sounds logical. Thank you for finding this reason, @davidwbarratt. I'm ok without this extension. In any case, config fpm out of Drupal tracker?

PHP Fatal error: Call to undefined function twig_template_get_attributes() in
It would be nice to make the description of this error more intelligible (With mention of the 'Twig C extension'). This will help to many developers, who change php5.x to php 7.x.Or goes to another hosting. Or like here, have difference configuration.

What about follow-up issue and close this like "Normal, Support request"?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.