Renderer Using A Chameleon Macro Name renders whole template after pyramid reloads the template #1013

Closed
Falmarri opened this Issue May 9, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@Falmarri

Falmarri commented May 9, 2013

If you have a renderer as such:

@view_config(renderer='foo#bar.pt')

and then change foo.pt, the renderer renders the entire foo.pt template on subsequent requests.

As far as I can tell this only applies to when pyramid.reload_templates is True.

Update:

So I've found the cause of this, but not any kind of reasonable solution. It might involve a fix in chameleon as well. The offending code is here in chameleon_zpt.py

    @reify
    def template(self): 
        tf = PageTemplateFile(
            self.path,
            auto_reload=self.lookup.auto_reload,
            debug=self.lookup.debug,
            translate=self.lookup.translate
            )   
        if self.macro:
            # render only the portion of the template included in a
            # define-macro named the value of self.macro
            macro_renderer = tf.macros[self.macro].include
            tf._render = macro_renderer
        return tf

This code is reified and returns the same PageTemplateFile object every time. But to get the macro rendering, pyramid changes the tf._render object after creating the object. But when chameleon goes to reload the template when it's changed (since it's chameleon, not pyramid doing that) it blows away the change to tf._render.

The "solution" that I did was change @reify to @property. But that causes the template to be reloaded every single time it's accessed, not just when it's changed.

@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

mcdonc Jul 18, 2013

Member

See also #1037

Member

mcdonc commented Jul 18, 2013

See also #1037

@Falmarri

This comment has been minimized.

Show comment
Hide comment
@Falmarri

Falmarri Jul 19, 2013

@mcdonc I'm not sure that's completely relevant to this bug. I'll edit my bug report to post how a did a workaround (extremely hacky)

@mcdonc I'm not sure that's completely relevant to this bug. I'll edit my bug report to post how a did a workaround (extremely hacky)

@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

mcdonc Aug 28, 2013

Member

Thanks for the succinct bug report here. I've made this a blocker for releasing 1.5.

Member

mcdonc commented Aug 28, 2013

Thanks for the succinct bug report here. I've made this a blocker for releasing 1.5.

@mcdonc mcdonc closed this in 8a7e80d Aug 29, 2013

mcdonc added a commit that referenced this issue Aug 29, 2013

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