snaql icon indicating copy to clipboard operation
snaql copied to clipboard

Macros cannot be used when kwargs present

Open meowcakes opened this issue 7 years ago • 1 comments

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

meowcakes avatar Sep 20 '17 06:09 meowcakes

I'll investigate this issue soon, thank you.

semirook avatar Sep 20 '17 12:09 semirook