Enable error checking on attribute names
oharboe opened this issue · 3 comments
When referring to an attribute that doesn't exist, no error is produced.
To enable errors:
from jinja2 import StrictUndefined
app.builder.templates.environment.undefined = StrictUndefined
The problem is that it enables errors for all jinja2 templates, including HTML templates.
I'd like to have errors enabled only for sphinxcontrib.datatemplates.
It looks like the SandboxedEnvironment() belongs to the builder. The datatemplates directive can therefore be invoked from any builder and the templates are loaded into a the enviornment of that builder.
Near as I can tell, to avoid modifying the environment temporarily, it's necessary to create a new builder with a SandboxedEnvironment() with undefined set as I do in this patch.
It seems a bit over the top to run a builder only to check that the jinja2 templates are valid.
This is odd though... datatemplates is not special. jinja2 is used pervasively in Sphinx. Why hasn't anyone else run into this??? I wasn't able to google anything...
Why would we need a whole new builder just to create a new environment? Does the SandboxedEnvironment use settings from the builder? Could we instantiate a new environment and give it the current builder?
Why would we need a whole new builder just to create a new environment? Does the SandboxedEnvironment use settings from the builder? Could we instantiate a new environment and give it the current builder?
I'm hoping for some pointers from the sphinx core team... Seems like they think this is a reasonable request without an obvious answer.
For my part I have a stop-gap solution, so I don't mind being a bit patient to let the answers tick in...