sqlfluff icon indicating copy to clipboard operation
sqlfluff copied to clipboard

Unrecoverable failure in Jinja templating: cannot unpack non-iterable UndefinedRecorder object

Open sukalpv opened this issue 1 year ago • 0 comments

Search before asking

  • [X] I searched the issues and found no similar issues.

What Happened

When formatting a sql file with jinja set var {% set a = ``}, the formatting doesn't work and lint command fails with error.

L:   1 | P:   1 |  TMP | Unrecoverable failure in Jinja templating: cannot unpack
                       | non-iterable UndefinedRecorder object. Have you
                       | correctly configured your variables?
                       | https://docs.sqlfluff.com/en/latest/configuration.html

Expected Behaviour

lint command should not fail and file should be formatted with sqlfluff fix

Observed Behaviour

lint command fails and runnig sqlfluff fix has no effect on sql

How to reproduce

Here is SQL to reproduce:

{{ config(
    schema='etl',
    materialized='table')
}}

{% set sessions_this_run = ref('snowplow_unified_base_sessions_this_run') %}
{% set lower_limit, upper_limit = snowplow_utils.return_limits_from_model(sessions_this_run, 'start_tstamp', 'end_tstamp') %}

SELECT DISTINCT event_id, derived_tstamp, agent_class, device_class
FROM  {{ ref('events_yauaa_context_tracker') }}
WHERE DATE(derived_tstamp) >= DATE({{ lower_limit }}) AND DATE(derived_tstamp) <= DATE({{ upper_limit }})

sqlfluff lint sqlfluff fix

Dialect

dialect: bigquery templating: jinja

Version

3.0.6

Configuration

[sqlfluff]
dialect = bigquery
templater = jinja
exclude_rules = ambiguous.column_count, structure.column_order, ambiguous.column_references, structure.unused_cte, references.qualification, ambiguous.join, structure.subquery, aliasing.unused, convention.left_join, structure.simple_case, convention.coalesce, structure.using, capitalisation.identifiers
max_line_length = 200
large_file_skip_byte_limit = 0
fix_even_unparsable = True

[sqlfluff:templater:jinja]
apply_dbt_builtins = true
load_macros_from_path = dags/dbt/models



[sqlfluff:indentation]
allow_implicit_indents = True
tab_space_size = 4

[sqlfluff:rules:aliasing.table]
aliasing = explicit
[sqlfluff:rules:aliasing.column]
aliasing = explicit
[sqlfluff:rules:aliasing.length]
min_alias_length = 1

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = upper

[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = lower

[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = lower

[sqlfluff:rules:layout.long_lines]
ignore_comment_lines = True
ignore_comment_clauses = True

[sqlfluff:rules:references.keywords]
ignore_words = user,source,target,domain,account,campaign,type,operation_id,timestamp,value,date,date_,label,language,cycle,stage,week,columns,name

Are you willing to work on and submit a PR to address the issue?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

sukalpv avatar May 17 '24 11:05 sukalpv