From 1fb3be841467f775701c0da9796ba5a5cf280d7a Mon Sep 17 00:00:00 2001 From: Bradley Shawyer Date: Fri, 6 Dec 2024 10:15:56 +0000 Subject: [PATCH 1/2] fix: LT05 panic when trying to remove elements from a sequence out of bounds --- .../fixtures/rules/std_rule_cases/LT05.yml | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/lib/test/fixtures/rules/std_rule_cases/LT05.yml b/crates/lib/test/fixtures/rules/std_rule_cases/LT05.yml index 9f1300f4c..55aaeec6c 100644 --- a/crates/lib/test/fixtures/rules/std_rule_cases/LT05.yml +++ b/crates/lib/test/fixtures/rules/std_rule_cases/LT05.yml @@ -713,3 +713,32 @@ test_pass_window_function: order by d desc ) as rnk from foo + +test_long_line_with_jinja_template: + # Test handling of long lines with Jinja templates to avoid index out of bounds + pass_str: | + {{ config( + materialized = 'table', + tags = ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tag10"] + ) }} + + WITH date_series AS ( + SELECT DATE(DATEADD(month, + ROW_NUMBER() OVER ( + PARTITION BY cm.customer_external_id, + cm.subscription_external_id, + cm.uuid + ORDER BY cm.date + ) - 1, + cm.date + ) AS calendar_date + FROM {{ source("some_schema", "some_table") }} AS cm + ) + SELECT * FROM date_series + configs: + core: + max_line_length: 80 + templater: + jinja: + context: + source: my_source From 9a5d2da684b5272c0d47157f43173705fef03e73 Mon Sep 17 00:00:00 2001 From: Bradley Shawyer Date: Fri, 6 Dec 2024 10:19:48 +0000 Subject: [PATCH 2/2] fix: check index in bounds before trying to remove. --- crates/lib/src/rules/layout/lt05.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/lib/src/rules/layout/lt05.rs b/crates/lib/src/rules/layout/lt05.rs index bfb6b0858..a7c489c3b 100644 --- a/crates/lib/src/rules/layout/lt05.rs +++ b/crates/lib/src/rules/layout/lt05.rs @@ -163,7 +163,15 @@ FROM my_table"# } for idx in to_remove { - results.remove(idx); + if idx < results.len() { + results.remove(idx); + } else { + println!( + "Attempted to remove index {} from results with length {}", + idx, + results.len() + ); + } } results