Composed def leads to infinite recursion

Issue #186 resolved
guest
created an issue

Okay, this time I'm almost positive this counts as a bug, as opposed to me doing something wierd.

This leads to a RuntimeError: maximum recursion depth exceeded.

from mako.template import Template

tmpl = Template(""" <%def name="f()">${caller.body()}</%def> <%def name="g()">${caller.body()}</%def>

<%def name="fg()"> <%self:f><%self:g>${caller.body()}</%self:g></%self:f> </%def>

<%self:fg>body</%self:fg> """)

print tmpl.render()

When I have a chance, I'll see if I can come up with a patch.

Comments (3)

  1. guest reporter

    Here's a patch. (I'm not positive this is the right fix.) (Patch is on mako-0.6.2 and includes a test case for this problem.)

  2. Michael Bayer repo owner

    I think it's the right fix (though granted this is really brain twisting code I could barely understand even when I was writing it), as what we're looking for with _get_caller() is what we pushed on with _push_frame(). I've consolidated in 936a524263b90071d601b09a63f3c86117769b61 so that _push_frame() just returns the value into `M_caller` - saves us a method call too ! thanks !

  3. guest reporter

    Replying to [comment:2 zzzeek]:

    I think it's the right fix (though granted this is really brain twisting code I could barely understand even when I was writing it)

    Good — it is two to zero for, then! (I'm glad to hear that you are human too :-)

    I've consolidated in 936a524263b90071d601b09a63f3c86117769b61 so that _push_frame() just returns the value into `M_caller` - saves us a method call too.

    Looks good. Thank you!

  4. Log in to comment