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

Does pongo2 support recursion template #279

Open
AlkaidChan opened this issue Dec 4, 2021 · 7 comments
Open

Does pongo2 support recursion template #279

AlkaidChan opened this issue Dec 4, 2021 · 7 comments

Comments

@AlkaidChan
Copy link

When I render a template "comment.html", use "{% include "comment.html" with comments=comment.SubComments %}, it led to a stack overflow,
I'm pretty sure my grammar is correct in django.

@flosch
Copy link
Owner

flosch commented Jun 24, 2022

Can you provide a minimal example in code which demonstrates the problem to have it debugged easier? Thanks.

@kimtore
Copy link

kimtore commented Jun 11, 2023

@AlkaidChan I'm having the same issue, did you come up with a solution?

@flosch
Copy link
Owner

flosch commented Jun 11, 2023

Can you provide a minimal working example of the potential bug so I can take a look? Thanks!

@kimtore
Copy link

kimtore commented Jun 11, 2023

This is the data, simply a struct that can have its own datatype as children.

type Post struct {
	ID          uuid.UUID
	Children    []*Post
	Message     *string
}

Template code:

<div class="post" data-id="{{ post.ID }}">
    <p>Message={{ post.Message }}</p>
    {% for child in post.Children %}
        {% include "posts/post.html" post=child %}
    {% endfor %}
</div>

@kimtore
Copy link

kimtore commented Jun 11, 2023

Eventually, my program crashes:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc072a80380 stack=[0xc072a80000, 0xc092a80000]
fatal error: stack overflow

runtime stack:
runtime.throw({0xc3383f?, 0x1193d40?})
        /usr/lib/go/src/runtime/panic.go:1047 +0x5d fp=0x7f8a5fffeca0 sp=0x7f8a5fffec70 pc=0x43993d
runtime.newstack()
        /usr/lib/go/src/runtime/stack.go:1105 +0x5bd fp=0x7f8a5fffee50 sp=0x7f8a5fffeca0 pc=0x4532bd
runtime.morestack()
        /usr/lib/go/src/runtime/asm_amd64.s:574 +0x8b fp=0x7f8a5fffee58 sp=0x7f8a5fffee50 pc=0x46a6eb

goroutine 103 [running]:
runtime.newobject(0xbd7880?)
        /usr/lib/go/src/runtime/malloc.go:1253 +0x3b fp=0xc072a80390 sp=0xc072a80388 pc=0x40fafb
github.com/flosch/pongo2/v6.(*Parser).parseSimpleExpression(0xc0eaacff00)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_expression.go:414 +0x3a fp=0xc072a80430 sp=0xc072a80390 pc=0xa3363a
github.com/flosch/pongo2/v6.(*Parser).parseRelationalExpression(0x40f70a?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_expression.go:461 +0x30 fp=0xc072a80518 sp=0xc072a80430 pc=0xa33a10
github.com/flosch/pongo2/v6.(*Parser).ParseExpression(0xc0eaacff00)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_expression.go:495 +0x33 fp=0xc072a805c0 sp=0xc072a80518 pc=0xa33d53
github.com/flosch/pongo2/v6.(*Parser).parseVariableElement(0xc0eaacff00)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/variable.go:750 +0xa5 fp=0xc072a80608 sp=0xc072a805c0 pc=0xa49045
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0x0?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:20 +0x6e fp=0xc072a80648 sp=0xc072a80608 pc=0xa3094e
github.com/flosch/pongo2/v6.(*Parser).parseDocument(0xc0eaacff00)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:51 +0x58 fp=0xc072a806b0 sp=0xc072a80648 pc=0xa30c98
github.com/flosch/pongo2/v6.(*Template).parse(0xc0eaab6c60)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:39 +0x11a fp=0xc072a806f8 sp=0xc072a806b0 pc=0xa30bda
github.com/flosch/pongo2/v6.newTemplate(0xc000462230, {0xc0eaaae680, 0x3f}, 0x0, {0xc0eaac3800?, 0xc0eaaae600?, 0x40?})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template.go:89 +0x1dc fp=0xc072a80758 sp=0xc072a806f8 pc=0xa3e87c
github.com/flosch/pongo2/v6.(*TemplateSet).FromFile(0xc000462230, {0xc0eaaae680, 0x3f})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template_sets.go:231 +0x1a7 fp=0xc072a807b0 sp=0xc072a80758 pc=0xa41127
github.com/flosch/pongo2/v6.tagIncludeParser(0xc0eaacef80, 0xc000455e60?, 0xc0eaacf080)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_include.go:91 +0x151 fp=0xc072a80828 sp=0xc072a807b0 pc=0xa3a331
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaacef80)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a80910 sp=0xc072a80828 pc=0xa347f5
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0x0?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:27 +0x92 fp=0xc072a80950 sp=0xc072a80910 pc=0xa30972
github.com/flosch/pongo2/v6.(*Parser).WrapUntilTag(0xc0eaacef80, {0xc072a80a80?, 0x2, 0x2})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser.go:257 +0x15a fp=0xc072a80a28 sp=0xc072a80950 pc=0xa3015a
github.com/flosch/pongo2/v6.tagForParser(0xc0eaacef80?, 0xc000455e60?, 0xc0eaacf040)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_for.go:131 +0x2f6 fp=0xc072a80ab0 sp=0xc072a80a28 pc=0xa37896
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaacef80)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a80b98 sp=0xc072a80ab0 pc=0xa347f5
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0xc0eaacef80?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:27 +0x92 fp=0xc072a80bd8 sp=0xc072a80b98 pc=0xa30972
github.com/flosch/pongo2/v6.(*Parser).parseDocument(0xc0eaacef80)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:51 +0x58 fp=0xc072a80c40 sp=0xc072a80bd8 pc=0xa30c98
github.com/flosch/pongo2/v6.(*Template).parse(0xc0eaab6b40)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:39 +0x11a fp=0xc072a80c88 sp=0xc072a80c40 pc=0xa30bda
github.com/flosch/pongo2/v6.newTemplate(0xc000462230, {0xc0eaaae600, 0x3f}, 0x0, {0xc0eaac3400?, 0xc0eaaae580?, 0x40?})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template.go:89 +0x1dc fp=0xc072a80ce8 sp=0xc072a80c88 pc=0xa3e87c
github.com/flosch/pongo2/v6.(*TemplateSet).FromFile(0xc000462230, {0xc0eaaae600, 0x3f})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template_sets.go:231 +0x1a7 fp=0xc072a80d40 sp=0xc072a80ce8 pc=0xa41127
github.com/flosch/pongo2/v6.tagIncludeParser(0xc0eaace000, 0xc000455e60?, 0xc0eaace100)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_include.go:91 +0x151 fp=0xc072a80db8 sp=0xc072a80d40 pc=0xa3a331
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaace000)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a80ea0 sp=0xc072a80db8 pc=0xa347f5
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0x0?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:27 +0x92 fp=0xc072a80ee0 sp=0xc072a80ea0 pc=0xa30972
github.com/flosch/pongo2/v6.(*Parser).WrapUntilTag(0xc0eaace000, {0xc072a81010?, 0x2, 0x2})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser.go:257 +0x15a fp=0xc072a80fb8 sp=0xc072a80ee0 pc=0xa3015a
github.com/flosch/pongo2/v6.tagForParser(0xc0eaace000?, 0xc000455e60?, 0xc0eaace0c0)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_for.go:131 +0x2f6 fp=0xc072a81040 sp=0xc072a80fb8 pc=0xa37896
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaace000)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a81128 sp=0xc072a81040 pc=0xa347f5
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0xc0eaace000?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:27 +0x92 fp=0xc072a81168 sp=0xc072a81128 pc=0xa30972
github.com/flosch/pongo2/v6.(*Parser).parseDocument(0xc0eaace000)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:51 +0x58 fp=0xc072a811d0 sp=0xc072a81168 pc=0xa30c98
github.com/flosch/pongo2/v6.(*Template).parse(0xc0eaab6a20)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:39 +0x11a fp=0xc072a81218 sp=0xc072a811d0 pc=0xa30bda
github.com/flosch/pongo2/v6.newTemplate(0xc000462230, {0xc0eaaae580, 0x3f}, 0x0, {0xc0eaac3000?, 0xc0eaaae500?, 0x40?})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template.go:89 +0x1dc fp=0xc072a81278 sp=0xc072a81218 pc=0xa3e87c
github.com/flosch/pongo2/v6.(*TemplateSet).FromFile(0xc000462230, {0xc0eaaae580, 0x3f})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template_sets.go:231 +0x1a7 fp=0xc072a812d0 sp=0xc072a81278 pc=0xa41127
github.com/flosch/pongo2/v6.tagIncludeParser(0xc0eaacb080, 0xc000455e60?, 0xc0eaacb180)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_include.go:91 +0x151 fp=0xc072a81348 sp=0xc072a812d0 pc=0xa3a331
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaacb080)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a81430 sp=0xc072a81348 pc=0xa347f5
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0x0?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:27 +0x92 fp=0xc072a81470 sp=0xc072a81430 pc=0xa30972
github.com/flosch/pongo2/v6.(*Parser).WrapUntilTag(0xc0eaacb080, {0xc072a815a0?, 0x2, 0x2})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser.go:257 +0x15a fp=0xc072a81548 sp=0xc072a81470 pc=0xa3015a
github.com/flosch/pongo2/v6.tagForParser(0xc0eaacb080?, 0xc000455e60?, 0xc0eaacb140)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_for.go:131 +0x2f6 fp=0xc072a815d0 sp=0xc072a81548 pc=0xa37896
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaacb080)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a816b8 sp=0xc072a815d0 pc=0xa347f5
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0xc0eaacb080?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:27 +0x92 fp=0xc072a816f8 sp=0xc072a816b8 pc=0xa30972
github.com/flosch/pongo2/v6.(*Parser).parseDocument(0xc0eaacb080)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:51 +0x58 fp=0xc072a81760 sp=0xc072a816f8 pc=0xa30c98
github.com/flosch/pongo2/v6.(*Template).parse(0xc0eaab6900)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:39 +0x11a fp=0xc072a817a8 sp=0xc072a81760 pc=0xa30bda
github.com/flosch/pongo2/v6.newTemplate(0xc000462230, {0xc0eaaae500, 0x3f}, 0x0, {0xc0eaac2c00?, 0xc0eaaae480?, 0x40?})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template.go:89 +0x1dc fp=0xc072a81808 sp=0xc072a817a8 pc=0xa3e87c
github.com/flosch/pongo2/v6.(*TemplateSet).FromFile(0xc000462230, {0xc0eaaae500, 0x3f})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/template_sets.go:231 +0x1a7 fp=0xc072a81860 sp=0xc072a81808 pc=0xa41127
github.com/flosch/pongo2/v6.tagIncludeParser(0xc0eaaca100, 0xc000455e60?, 0xc0eaaca200)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_include.go:91 +0x151 fp=0xc072a818d8 sp=0xc072a81860 pc=0xa3a331
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaaca100)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a819c0 sp=0xc072a818d8 pc=0xa347f5
github.com/flosch/pongo2/v6.(*Parser).parseDocElement(0x0?)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser_document.go:27 +0x92 fp=0xc072a81a00 sp=0xc072a819c0 pc=0xa30972
github.com/flosch/pongo2/v6.(*Parser).WrapUntilTag(0xc0eaaca100, {0xc072a81b30?, 0x2, 0x2})
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/parser.go:257 +0x15a fp=0xc072a81ad8 sp=0xc072a81a00 pc=0xa3015a
github.com/flosch/pongo2/v6.tagForParser(0xc0eaaca100?, 0xc000455e60?, 0xc0eaaca1c0)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags_for.go:131 +0x2f6 fp=0xc072a81b60 sp=0xc072a81ad8 pc=0xa37896
github.com/flosch/pongo2/v6.(*Parser).parseTagElement(0xc0eaaca100)
        /home/kimt/go/pkg/mod/github.com/flosch/pongo2/[email protected]/tags.go:129 +0x575 fp=0xc072a81c48 sp=0xc072a81b60 pc=0xa347f5

... and so on.

@kimtore
Copy link

kimtore commented Jun 15, 2023

@flosch did you have a chance to take a look at this, and perhaps reproduce?

Recursion is a must for me here, I'd really rather not have to write a bunch of custom template tags or other creative solutions to solve this.

@flosch
Copy link
Owner

flosch commented Jun 15, 2023

Did not had time yet, but it's on my todo list; no ETA though unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants