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.

Linting some files results in IndexError: list index out of range slicing error

See original GitHub issue

Using dbt templater and 0.4.0a3. Full stacktrace:

Traceback (most recent call last):
  File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/bin/sqlfluff", line 11, in <module>
    load_entry_point('sqlfluff', 'console_scripts', 'sqlfluff')()
  File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/cli/commands.py", line 323, in lint
    ignore_files=not disregard_sqlfluffignores,
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 1161, in lint_paths
    ignore_files=ignore_files,
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 1139, in lint_path
    target_file.read(), fname=fname, fix=fix, config=config
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 939, in lint_string
    parsed = self.parse_string(in_str=in_str, fname=fname, config=config)
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 723, in parse_string
    tokens, lex_vs = lexer.lex(templated_file)
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/parser/lexer.py", line 343, in lex
    return self.enrich_segments(segment_buff, raw), violations
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/parser/lexer.py", line 373, in enrich_segments
    templated_slice
  File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/templaters/base.py", line 283, in templated_slice_to_source_slice
    elif start_slices[0][0] == "literal":
IndexError: list index out of range

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
alanmcruickshankcommented, Jan 6, 2021

I think the comment I added to #603 about slicing and the missing bits is probably spot on in what’s causing this issue. The templating code wasn’t designed to deal with query wrapping like this because the bits aren’t in the source at all.

@NiallRees - want me to pick this up or are those pointers enough for you to have a go?

0reactions
NiallReescommented, Jan 11, 2021

Having just looked a bit further into the code - I think it will take me so long to get my head around it it might not be worth it as you wrote it relatively recently. I’ll keep my efforts focused where I can contribute more effectively for now - you ok to pick this one up?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python IndexError: List Index Out of Range [Easy Fix] - Finxter
What is this? The error “list index out of range” arises if you access invalid indices in your Python list. For example, if...
Read more >
How to Fix IndexError in Python - Rollbar
The IndexError in Python occurs when an item from a list is attempted to be accessed that is outside the index range of...
Read more >
Python indexerror: list index out of range Solution
This error message tells us that we're trying to access a value inside an array that does not have an index position. ......
Read more >
getting Error msg: List index out of range while slicing a list?
This doesn't account for the IndexError that the OP is seeing, though. My hypothesis is that one of the split('--') calls is returning...
Read more >
MATLAB vs Python: Why and How to Make the Switch
This file is meant as a temporary place to try things out before you save them ... Python lists have some important distinctions...
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