Weird error in templates

Hi (this is my first post here),

I am designing a template for Renku and was fighting with a weird error due to Jinja2. I got this error when I use the template within the UI (New project):

Errors occurred while creating the project.
internal error

… not very informative. Using it from the Renku CLI gives a little bit more details:

...
handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<unknown>", line 25, in template
jinja2.exceptions.TemplateSyntaxError: Missing end of comment tag

I found the problem. It is in one of the .R scripts in the template that uses some common R code, like:

if (x) {# This is a comment
  code_to_run
}

The problem: in a template all files are screened by Jinja2 and the {# construct is a Jinja tag that indicates the start of a comment… and there is no corresponding ‘#}’ tag. So, it raises an error… pfiouuu!

I think it should be very important to state in the Renku documentation that all files in a template are screened by Jinja2 and that one has to take care of special Jinja tags like this one, or {{, that are not unfrequent constructs in R code, for instance!

1 Like

Hi Philippe!

thanks a lot for reporting this!
indeed both of the ones you’ve mentioned are default delimiters of Jinja2.

Jinja2 allows changing the these default delimiters and as you’ve mentioned in R both of the mentioned statements can occur it might be a good idea to change these default jinja2 delimiters.

We’ll look into how it would be the best/quickest way to resolve this problem.

ta!

btw: just a quickfix for the time being you can overcome these errors you could use escaping in the templates of course, but i guess you’ve seen this already in Jinja2’s documentation.

It would be nice to change the tags to avoid conflict with R code, but I think it is already enough to emphasize in the Renku documentation that tags {{, }}, {%, %}, {#, and #} should not be used in any files in the template, except for Jinja2 commands.

just a follow-up question: the code that collides actually with jinja2 is actually part of a template itself, or the file that contains that code section is just part of the the template repository that you are preparing, but that file does not contain any templated variable? in other words, jinja2 actually does not have any effect (apart from the current error that you are getting) on that specific file…?

The template is in a folder bds2021 in this repo: GitHub - SciViews/renku-project-template: A repository for Renku project templates for SciViews.</, if you want to take a look at it. There are three variables defined: description, user_data and github_pat. These variables are not replaced in the R scripts contained in the template, but in other files. I don’t know if it is possible to filter the files that are screened by Jinja2? Something like .jinjaignore that would contain in my case *.r and *.py.