Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception where node isn't callable #1414

Closed
wants to merge 1 commit into from

Conversation

MacilPrime
Copy link

I've been trying to upgrade my Tinyboard fork's version of Twig to 1.15.1 from a several years old version. Tinyboard uses the Twig I18n extension (I updated the Extensions folder to Twig-extensions v1.0.1), and an extension of its own that just adds some simple filters. I started getting this exception on most pages after updating Twig:

Fatal error: Uncaught exception 'LogicException' with message 'Attribute "callable" does not exist for Node "Twig_Node_Expression_Function".' in /home/mlpchan/www/dev/inc/lib/Twig/Node.php:141
Stack trace:
#0 /home/mlpchan/www/dev/inc/lib/Twig/Node/Expression/Call.php(15): Twig_Node->getAttribute('callable')
#1 /home/mlpchan/www/dev/inc/lib/Twig/Node/Expression/Function.php(33): Twig_Node_Expression_Call->compileCallable(Object(Twig_Compiler))
#2 /home/mlpchan/www/dev/inc/lib/Twig/Compiler.php(97): Twig_Node_Expression_Function->compile(Object(Twig_Compiler))
#3 /home/mlpchan/www/dev/inc/lib/Twig/Node/Print.php(35): Twig_Compiler->subcompile(Object(Twig_Node_Expression_Function))
#4 /home/mlpchan/www/dev/inc/lib/Twig/Node.php(105): Twig_Node_Print->compile(Object(Twig_Compiler))
#5 /home/mlpchan/www/dev/inc/lib/Twig/Node.php(105): Twig_Node->compile(Object(Twig_Compiler))
#6 /home/mlpchan/www/dev/inc/lib/Twig/Compiler.php(97): Twig_Node->compile(Object(Twig_Compiler))
#7 /home/mlpchan/www/dev/inc/lib/Twig/Node/For.php(89) in /home/mlpchan/www/dev/inc/lib/Twig/Environment.php on line 564

I think this issue in another project is related: kolber/stacey#91

I notice that Twig_Node_Expression_Function only sometimes sets the 'callable' attribute on itself. Call.php appears to have logic for handling the callable attribute not being set, but it forgets to actually catch the exception if it's not set. I added a try-catch block, and things seem to be all working now. I'm not familiar with the Twig codebase, so someone else will have to judge the correctness of this.

Twig_Node::getAttribute throws an exception if the node doesn't have the given attribute. Call.php has code to deal with the node having a falsy 'callable' attribute, but doesn't handle the case where the node doesn't have a callable attribute.
@fabpot
Copy link
Contributor

fabpot commented May 27, 2014

Can you reproduce this error with a simple Twig template? Being able to reproduce it would help a lot in fixing the issue the right way.

@fabpot
Copy link
Contributor

fabpot commented Jul 5, 2014

I've tried to reproduce the error with no luck so far (the i18n extension works fine for me in version 1.0.1 and Twig master).

But anyway, I've made the code more robust in 23efa7b, so you won't have the issue anymore.

@fabpot fabpot closed this Jul 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants