-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Nested dict argument to jinja macro fails the formatter #471
Comments
I can't repro on
|
I've run into a similar issue -- plugging the code into sqlfmt.com works fine though, so I'm just manually replacing the buggy code Original code:
After formatting:
|
Can you run pip list, please? I need to know what versions of shandy-sqlfmt and black you have installed. |
I have a pretty long list of dependencies, but in my project I'm using
Some additional debugging messages, in case it's useful:
|
Thanks. Those logs are surprising -- the error is coming from pos 310, after later parts of the query are lexed... can you share the rest of your query (or another reproducible example), through the end of the where clause? |
This query triggers {{
config(
materialized='incremental',
incremental_strategy='insert_overwrite',
external_location=generate_external_location("baz", "datalake/producer=foo/object=bar"),
partitioned_by=['batch_date'],
lf_tags_config={
'enabled': true,
'tags': {
'domain': 'foo',
'sensitivity': 'public'
}
}
)
}}
select
batch_date
from
{{ ref('bar') }}
{% if is_incremental() %}
where batch_date = '{{ var("ds") }}'
{% endif %} The issue seems linked to the line-length argument. Running I've pinpointed the lack of a trailing comma as the issue -- if you add the comma before running sqlfmt, no errors are raised. lf_tags_config={
'enabled': true,
'tags': {
'domain': 'foo',
'sensitivity': 'public'
+ },
} |
I can reproduce on |
Looks like it's an issue with the
The correct start should be 94, and the correct end should be 96
On lengths < 95, the source_string doesn't have
It might be possible to solve this with some kind of parsing logic that checks the tail to see if it contains a dictionary. Otherwise, maybe some kind of initial pass to add trailing commas to } delimiters? That would prevent the end of the dictionary from being read as a jinja comment, since it becomes |
Raised a proper PR on this https://github.com/tconbeer/sqlfmt/pull/508/files -- it's a bit rough around the edges but hopefully is a step forwards. |
Thanks so much! I've been traveling - it's on my list to review this and get the other one merged today; might slip to early next week. Really appreciate your engagement here! |
Describe the bug
The following config macro makes the formatter fail because of the nested dict (range in partition_by)
To Reproduce
Paste the macro above in an sql file and try to run the formatter
Expected behavior
Formatter not erroring out
Actual behavior
Additional context
What is the output of
sqlfmt --version
?The text was updated successfully, but these errors were encountered: