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

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

@Falmarri
Copy link

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
Copy link
Member

mcdonc commented Jul 18, 2013

See also #1037

@Falmarri
Copy link
Author

@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
Copy link
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 as completed 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
Projects
None yet
Development

No branches or pull requests

2 participants