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

  1. Figure out Problem
  2. Write Patch

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

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.

Anonymous’s picture

davidwbarratt’s picture

Issue summary: View changes
Anonymous’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):
https://github.com/phototech/sailvenice

Anonymous’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.

Anonymous’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.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

markhalliwell’s picture

Version: 8.5.x-dev » 8.6.x-dev
Status: Needs review » Active

No patch

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Status: Active » Closed (works as designed)
Issue tags: +Bug Smash Initiative

Marking this closed based on the original reporter @davidwbarratt saying he resolved the issue in #12.