Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLFluff fails when dbt test is disabled #2836

Closed
3 tasks done
courentin opened this issue Mar 10, 2022 · 2 comments
Closed
3 tasks done

SQLFluff fails when dbt test is disabled #2836

courentin opened this issue Mar 10, 2022 · 2 comments
Labels
awaiting feedback Cannot continue investigating until more information is provided. bug Something isn't working dbt Related to Data Build Tool

Comments

@courentin
Copy link

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Similar to #931 it seems that when a test is disabled, sqlfluff will fail.

Expected Behaviour

Skip the sql file

Observed Behaviour

sqlfluff fails with this error message:

file coucou copy.sql:  86%|█████████████████████████████████████████████████████████████████████████████▌            | 81/94 [02:28<00:12,  1.08it/s]Traceback (most recent call last):                                                                                                                   
  File "/usr/local/bin/sqlfluff", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/cli/commands.py", line 533, in lint
    result = lnt.lint_paths(
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter/linter.py", line 1061, in lint_paths
    self.lint_path(
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter/linter.py", line 1013, in lint_path
    for i, linted_file in enumerate(runner.run(fnames, fix), start=1):
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter/runner.py", line 101, in run
    for fname, partial in self.iter_partials(fnames, fix=fix):
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter/runner.py", line 54, in iter_partials
    for fname, rendered in self.iter_rendered(fnames):
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter/runner.py", line 43, in iter_rendered
    yield fname, self.linter.render_file(fname, self.config)
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter/linter.py", line 734, in render_file
    return self.render_string(raw_file, fname, config, encoding)
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter/linter.py", line 705, in render_string
    templated_file, templater_violations = self.templater.process(
  File "/usr/local/lib/python3.8/site-packages/sqlfluff_templater_dbt/templater.py", line 323, in process
    processed_result = self._unsafe_process(fname_absolute_path, in_str, config)
  File "/usr/local/lib/python3.8/site-packages/sqlfluff_templater_dbt/templater.py", line 443, in _unsafe_process
    node = self._find_node(fname, config)
  File "/usr/local/lib/python3.8/site-packages/sqlfluff_templater_dbt/templater.py", line 398, in _find_node
    raise RuntimeError(
RuntimeError: File /workspaces/data-transformation/tests/prepared/coucou copy.sql was not found in dbt project

How to reproduce

Put a sql file with

{{ config(enabled=false) }}

in your model directory and another one in your test directory.

sqlfluff will fail for the one in test but not the one in model

Dialect

snowflake

Version

sqlfluff, version 0.11.0
Python 3.8.12

Configuration

.sqlfluff:

[sqlfluff]
exclude_rules = L007, L029, L031, L032, L034, L042, L043, L054
templater = dbt
dialect = snowflake

[sqlfluff:rules]
max_line_length = 100

[sqlfluff:rules:L030]  # Function names
capitalisation_policy = upper

.sqlfluffignore:

target/
dbt_modules/
macros/

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

@courentin courentin added the bug Something isn't working label Mar 10, 2022
@tunetheweb tunetheweb added the dbt Related to Data Build Tool label Mar 11, 2022
@barrywhart
Copy link
Member

Please provide more detail on how to reproduce the problem. Both of these work for me.

root@5767511f32db:/app/my-dbt# sqlfluff lint models/issue_2836_model.sql 
=== [dbt templater] Sorting Nodes...
19:52:22  Unable to do partial parsing because profile has changed
=== [dbt templater] Compiling dbt project...
=== [dbt templater] Project Compiled.
WARNING    Skipped file /app/my-dbt/models/issue_2836_model.sql because the model was disabled 
All Finished 📜 🎉!
root@5767511f32db:/app/my-dbt# sqlfluff lint tests/issue_2836_test.sql 
=== [dbt templater] Sorting Nodes...
=== [dbt templater] Compiling dbt project...
=== [dbt templater] Project Compiled.
WARNING    Skipped file /app/my-dbt/tests/issue_2836_test.sql because the model was disabled 
All Finished 📜 🎉!

@barrywhart barrywhart added the awaiting feedback Cannot continue investigating until more information is provided. label Mar 13, 2022
@tunetheweb
Copy link
Member

Closing due to lack of feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback Cannot continue investigating until more information is provided. bug Something isn't working dbt Related to Data Build Tool
Projects
None yet
Development

No branches or pull requests

3 participants