Open gergelylendvai opened 1 year ago
Hi, I have found a similar issue, also related to the length of the line. sqlfluff version 2.1.1 dbt-core: 1.3.3 dbt-bigquery: 1.3.0
Sqlfluff fix on the following code:
select
{{ dbt_utils.generate_surrogate_key(['abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc']) }} as dummy
renders the result:
select
{{ dbt_utils.generate_surrogate_key(['abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc']) }}
{{ dbt_utils.generate_surrogate_key(['abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc']) }}
as dummy
it adds a bunch of newlines and duplicates the jinja code. This only happens when the line is long enough to trigger LT05 too long line. If I shorten the line the bug is not triggered, if I add another linting error that gets fixed it still does not trigger the bug. this is the output when the bug is triggered, there is only LT05 being fixed.
== [models/staging/typeform/stg_typeform__logic_action_condition.sql] FAIL
L: 2 | P: 5 | LT05 | Line is too long (213 > 140).
| [layout.long_lines]
==== fixing violations ====
1 fixable linting violations found
Are you sure you wish to attempt to fix these? [Y/n] ...
I think the same is happening in my code. Formatting duplicated the coalesce_columns_by_prefix
Jinja macro:
from {{ ref('snowplow_ecommerce_base_events_this_run') }} as t,
UNNEST(
{{ snowplow_ecommerce.coalesce_columns_by_prefix(ref('snowplow_ecommerce_base_events_this_run'), 'contexts_com_snowplowanalytics_snowplow_ecommerce_product_1') }}
{{ snowplow_ecommerce.coalesce_columns_by_prefix(ref('snowplow_ecommerce_base_events_this_run'), 'contexts_com_snowplowanalytics_snowplow_ecommerce_product_1') }}
)
as r
with offset as index
)
I'm encountering this, too, on 3.0.1
Search before asking
What Happened
I tried to use the pre-commit hook with
sqlfluff fix
and change the following modelhowever it duplicated the first line with the
dbt_utils.star
macroIt's pretty similar to this issue, however the solution seems to not cover this case.
Expected Behaviour
The expected behaviour would be not to duplicate the line containing the macro.
Observed Behaviour
Here are the logs I've collected:
and I think this is the relevant part:
How to reproduce
Versions:
pre-commit-config.yaml
.sqlfluff
my_model.sql
Run:
Dialect
snowflake
Version
2.0.7
Configuration
pre-commit-config.yaml
.sqlfluff
my_model.sql
Are you willing to work on and submit a PR to address the issue?
Code of Conduct