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

Enable error checking on attribute names #84

Open
oharboe opened this issue Sep 2, 2021 · 3 comments
Open

Enable error checking on attribute names #84

oharboe opened this issue Sep 2, 2021 · 3 comments

Comments

@oharboe
Copy link
Contributor

oharboe commented Sep 2, 2021

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.

@oharboe
Copy link
Contributor Author

oharboe commented Sep 3, 2021

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...

@dhellmann
Copy link
Member

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?

@oharboe
Copy link
Contributor Author

oharboe commented Sep 3, 2021

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...

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

No branches or pull requests

2 participants