Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
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:
https://github.com/phototech/sailvenice/blob/develop/web/themes/custom/s...
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
- Figure out Problem
- Write Patch
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
davidwbarratt CreditAttribution: davidwbarratt as a volunteer commentedComment #3
davidwbarratt CreditAttribution: davidwbarratt for Sail Venice commentedComment #4
davidwbarratt CreditAttribution: davidwbarratt for Sail Venice commentedComment #5
cilefen CreditAttribution: cilefen commentedThis is major by our definition.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedMaybe a similar situation was in #2824220: php 7, I am getting the white screen of death (problem with absence Twig C extension)
Comment #7
davidwbarratt CreditAttribution: davidwbarratt for Sail Venice commentedComment #8
Anonymous (not verified) CreditAttribution: Anonymous commented@davidwbarratt, try to delete the folder
sites/default/files/php/twig
.Comment #9
davidwbarratt CreditAttribution: davidwbarratt for Sail Venice commentedIf I try and run `cron` this is what I get:
If I delete that folder:
It does fix the issue:
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...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.
Comment #10
davidwbarratt CreditAttribution: davidwbarratt for Sail Venice commentedIf it helps at all, the code base for the whole site is located here (sans some proprietary scss and javascript):
https://github.com/phototech/sailvenice
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedMaybe
/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)?Comment #12
davidwbarratt CreditAttribution: davidwbarratt for Sail Venice commentedSo... 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.
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commented#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"?
Comment #16
markhalliwellNo patch
Comment #21
pameeela CreditAttribution: pameeela commentedMarking this closed based on the original reporter @davidwbarratt saying he resolved the issue in #12.