Closed
Description
Describe the bug
jinjafmt passes jinja to black, but jinja allows some things that python does not. Specifically, variables (esp. macro arguments) can have names that are reserved words. For example:
{{ dbt_utils.star(from=ref('snowplow_page_views_30'), except=fields_to_exclude|upper) }}
This is valid jinja and dbt sql (from gitlab's project), but from
and except
are both reserved words in python. Running black -c "from"
returns error: cannot format <string>: Cannot parse: 1:4: from
Right now jinjafmt no-ops in these situations, but it wouldn't be that hard to replace these reserved words (followed by an eq, e.g. from=
) with a sentinel (e.g., from__sqlfmt__=
), format that, and then replace the sentinel with the keyword again. There are 33 reserved words in python