question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected exception: tuple index out of range (L019)

See original GitHub issue

Expected Behaviour

Including configuration

[sqlfluff:rules:L019]
comma_style = leading

does not lead to critical exception.

Observed Behaviour

Running sqlfluff lint models/dwh/best_model.sql with the config below causes exception.

(venv) ➜  ✗ sqlfluff lint models/dwh/best_model.sql
CRITICAL   [L019] Applying rule L019 threw an Exception: tuple index out of range
Traceback (most recent call last):
  File "/Users/justinwagg/Documents/data/venv/lib/python3.8/site-packages/sqlfluff/core/rules/base.py", line 282, in crawl
    res = self._eval(
  File "/Users/justinwagg/Documents/data/venv/lib/python3.8/site-packages/sqlfluff/core/rules/std.py", line 2218, in _eval
    last_seg = self._last_code_seg(raw_stack)
  File "/Users/justinwagg/Documents/data/venv/lib/python3.8/site-packages/sqlfluff/core/rules/std.py", line 2133, in _last_code_seg
    if raw_stack[idx].is_code or raw_stack[idx].is_type("newline"):
IndexError: tuple index out of range
CRITICAL   [L019] Applying rule L019 threw an Exception: tuple index out of range
Traceback (most recent call last):
  File "/Users/justinwagg/Documents/data/venv/lib/python3.8/site-packages/sqlfluff/core/rules/base.py", line 282, in crawl
    res = self._eval(
  File "/Users/justinwagg/Documents/data/venv/lib/python3.8/site-packages/sqlfluff/core/rules/std.py", line 2218, in _eval
    last_seg = self._last_code_seg(raw_stack)
  File "/Users/justinwagg/Documents/data/venv/lib/python3.8/site-packages/sqlfluff/core/rules/std.py", line 2133, in _last_code_seg
    if raw_stack[idx].is_code or raw_stack[idx].is_type("newline"):
IndexError: tuple index out of range
== [models/dwh/best_model.sql] FAIL
L:   1 | P:   1 | L019 | Unexpected exception: tuple index out of range; Could
                       | you open an issue at
                       | https://github.com/sqlfluff/sqlfluff/issues ? You can
                       | ignore this exception for now, by adding '--noqa: L019'
                       | at the end of line 1
L:   2 | P:   1 | L019 | Unexpected exception: tuple index out of range; Could
                       | you open an issue at
                       | https://github.com/sqlfluff/sqlfluff/issues ? You can
                       | ignore this exception for now, by adding '--noqa: L019'
                       | at the end of line 2
L:   4 | P:   1 | L003 | Indent expected and not found compared to line #3
L:   5 | P:   1 | L003 | Indent expected and not found compared to line #3

Removing

[sqlfluff:rules:L019]
comma_style = leading

fixes the issue.

Steps to Reproduce

Model:

-- models/dwh/best_model.sql
{{
  config(
    materialized='incremental',
    unique_key='field_1'
  )
}}

select field_1
,field_2
,field_3
from my_great_table
(venv) ➜ ✗ sqlfluff lint models/dwh/best_model.sql

Version

Include the output of sqlfluff --version along with your Python version

(venv) ➜ ✗ python -V
Python 3.8.0
(venv) ➜ ✗ sqlfluff --version
sqlfluff, version 0.4.0a3

Configuration

[sqlfluff]
templater = dbt
dialect = bigquery
exclude_rules = L036,L009,L008

[sqlfluff:indentation]
indented_joins = False

[sqlfluff:rules:L019]
comma_style = leading

[sqlfluff:rules:L003]
lint_templated_tokens = False

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
NiallReescommented, Jan 17, 2021

sqlfluff, version 0.3.6

OK cool. The part that’s failing in your stack trace has been totally changed in 0.4.0 - can you try it with 0.4.0a3?

1reaction
MinchoGcommented, Jan 17, 2021

Oh LOL

==== fixing violations ====
1983 fixable linting violations found
Are you sure you wish to attempt to fix these? [Y/n] ...
Attempting fixes...
Persisting Changes...
== [5_WAREHOUSE/F_MIXPANEL_EVENTS.sql] PASS
Done. Please check your files to confirm.

Thanks a bunch!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

IndexError: tuple index out of range in Python | bobbyhadz
The Python IndexError: tuple index out of range occurs when we try to access an index that doesn't exist in a tuple.
Read more >
IndexError: tuple index out of range ----- Python - Stack Overflow
28. I was getting this message because I was passing an array to a function that was expecting a variadic sequence of arguments...
Read more >
Python IndexError: tuple index out of range Solution
When you try to access an item in a tuple that does not exist, Python returns an error that says “tuple index out...
Read more >
[Solved]: Python IndexError: tuple index out of range
When user try access an item in a tuple that is out of range the Python returns an error that says “IndexError: tuple...
Read more >
IndexError: Python tuple index out of range - ArrowHiTech
In this guide, we explain what Tuple index out of range error means, why it is raised and The effective solution for this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found