Closed ngenain closed 4 years ago
For posterity, this is how variable scoping works in Jinja. This stackoverflow answer has more details and workarounds - https://stackoverflow.com/questions/60725409/variable-set-using-the-set-operator-are-not-being-propagated-to-the-parent-templ
Hi,
I am having an issue with template inheritance and sqlsafe: the argument doesn't seem to propagate in the inherited templates. Here is a toy example showing my problem: . ├── templates │ ├── tables.sql │ └── test.sql └── test.py
In tables.sql you have listed all your tables you want to include in other sql files. For instance here's the content of tables.sql
{% set test_table = 'test' | sqlsafe %}
In test.sql you include tables.sql
And in test.py I have the following code:
The answer is
The sqlsafe hasn't "survived" template inheritance. I also tried putting the sqlsafe parameter in the tables.sql and I got this answer:
Am I missing something?
Thank you very much for your help