L001 fix error: `NotImplementedError: Unexpected scenario during insert opcode!`
See original GitHub issueQuery which generates the error:
{% set party_types = (
'a', 'b', 'c'
) %}
select
parties.id
{% for party in party_types %}
, case when sum(case when very_long_name_of_thing.party_type = '{{party}}' then 1 else 0 end) > 0 then false else true end as {{party_type}}_blah_blah_blah
{% endfor %}
from parties
L: 5 | P: 1 | L001 | Unneccessary trailing whitespace.
L: 7 | P: 1 | L001 | Unneccessary trailing whitespace.
L: 9 | P: 1 | L001 | Unneccessary trailing whitespace.
L: 11 | P: 1 | L001 | Unneccessary trailing whitespace.
File "/Users/.../venv/lib/python3.7/site-packages/sqlfluff/linter.py", line 302, in fix_string
("Unexpected scenario during insert opcode! Please report "
NotImplementedError: Unexpected scenario during insert opcode! Please report this issue on github with the query and rules you're trying to fix.
I think the issue here isn’t actually with the linter, but that the rule is being incorrectly triggered as there isn’t any trailing whitespace in the query.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
DataFrame - If statement resulting in NotImplementedError ...
I am trying to add a new column to a DataFrame after performing checks on the value of two other columns. The conditional...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The templating problem is an interesting one! My thoughts on this is that the solution should revolve around tagging templated segments.
It would allow us to:
@NiallRees raised many great issues to implement DBT best practices through sqlfluff that are only possible if we read and understand the code pre-templating. (For example
{{ ref("...") }}
should be inside a CTE at the top of the file.)I think it should look more like this:
This is the kind of problem where linting post templating becomes difficult, because as a user you’d never see the templated code and so don’t care what it looks like, but sqlfluff does. The goal is to make the pre-templated code readable, which in this case I think it is. I imagine this won’t be the only case where this crops up