snaql
snaql copied to clipboard
Macros cannot be used when kwargs present
Hello,
If I define a macro in my queries file and then use it in a SQL block like this:
{% macro foo() %}
hello
{% endmacro %}
{% sql 'bar' %}
select * from {{ foo() }}
{% endsql %}
>> queries.bar()
it works as expected, and the resulting query string is select * from hello
However, if my SQL block accepts keyword arguments and I pass a keyword argument, like this:
{% macro foo() %}
hello
{% endmacro %}
{% sql 'bar' %}
select {{ baz }} from {{ foo() }}
{% endsql %}
>> queries.bar(baz='quux')
Then the following exception is produced jinja2.exceptions.UndefinedError: 'foo' is undefined
It seems like snaql has separate logic for when kwargs
is present: https://github.com/semirook/snaql/blob/master/snaql/factory.py#L202
Would a fix be possible? Thanks
I'll investigate this issue soon, thank you.