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

Issue with jinja call and endcall syntax with v0.14.0 #335

Closed
AndrewLane opened this issue Dec 5, 2022 · 8 comments · Fixed by #336
Closed

Issue with jinja call and endcall syntax with v0.14.0 #335

AndrewLane opened this issue Dec 5, 2022 · 8 comments · Fixed by #336
Labels
bug Something isn't working

Comments

@AndrewLane
Copy link

Describe the bug
sqlfmt error with jinja syntax for start and endcall that used to parse previously.

To Reproduce
Run sql-fmt on the following code:

{% call dbt_unit_testing.mock_ref('some_table') %}
id | foo
1 | 2022
{% endcall %}

Expected behavior
Should not fail to parse

Actual behavior

sqlfmt encountered an error: Encountered closing bracket '{% endcall %}' at position xxx, before matching opening bracket. Context: {% endcall %}

Additional context
Version v0.14.0 appears to break this

@tconbeer
Copy link
Owner

tconbeer commented Dec 5, 2022

I thought the contents of a call block have to be sql? I'm not familiar with the dbt_unit_testing package -- could you explain to me what this code does?

@AndrewLane
Copy link
Author

{% call dbt_unit_testing.mock_ref('some_table') %}
id | foo
1 | 2022
{% endcall %}

Sorry probably a strange sample without context. But I can confirm that if you replace it with SQL it still fails, if that helps?

{% call dbt_unit_testing.mock_ref('some_table') %}
select * from foo
{% endcall %}

@AndrewLane
Copy link
Author

And an even more simple example fails as well:

{% call foo() %}
select * from foo
{% endcall %}

@tconbeer
Copy link
Owner

tconbeer commented Dec 5, 2022

ok, I see the problem... I thought in dbt, the call blocks have to be labeled {% call statement(...) %} or {% call noop_statement(...) %} -- it seems the package is creating new jinja macros called mock_ref, etc., and calling those with the call syntax? I actually didn't realize that was possible. Are these equivalent?

{% set args %}
select * from foo
{% endset %}
{{ foo(args) }}

The reason I ask is because for call statement blocks, I know the contents have to be SQL, but for arbitrary set or call blocks, they can be data (as in your original example), so we'd need to skip formatting them entirely

@AndrewLane
Copy link
Author

ok, I see the problem... I thought in dbt, the call blocks have to be labeled {% call statement(...) %} or {% call noop_statement(...) %} -- it seems the package is creating new jinja macros called mock_ref, etc., and calling those with the call syntax? I actually didn't realize that was possible. Are these equivalent?

{% set args %}
select * from foo
{% endset %}
{{ foo(args) }}

The reason I ask is because for call statement blocks, I know the contents have to be SQL, but for arbitrary set or call blocks, they can be data (as in your original example), so we'd need to skip formatting them entirely

Well, I wouldn't say the contents have to be SQL, because that same library allows you to specify your mock data as CSV as shown here: https://github.com/EqualExperts/dbt-unit-testing#different-ways-to-build-mock-values

@AndrewLane
Copy link
Author

@tconbeer Thanks! Will look for a new version with this change and try it out...

@tconbeer
Copy link
Owner

tconbeer commented Dec 6, 2022

@AndrewLane 0.14.1 just hit PyPI

@AndrewLane
Copy link
Author

@AndrewLane 0.14.1 just hit PyPI

I'm actually still having trouble (I guess I made my steps to repro too simple) so I'll open up a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants