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 model is disabled #931

Closed
dwallace0723 opened this issue Apr 6, 2021 · 4 comments · Fixed by #949
Closed

SQLFluff fails when dbt model is disabled #931

dwallace0723 opened this issue Apr 6, 2021 · 4 comments · Fixed by #949
Assignees
Labels
bug Something isn't working

Comments

@dwallace0723
Copy link

if a dbt model is disabled (i.e. has configuration of enabled = false) sqlfluff will fail with the following internal error:

dbt@e5d0121500ec:/workspaces/dbt-dutchie$ sqlfluff lint models/shared/ga_daily_sessions.sql
WARNING    Unable to lint models/shared/ga_daily_sessions.sql due to an internal error. Please report this as an issue with your query's contents and stacktrace below!
To hide this warning, add the failing file to .sqlfluffignore
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter.py", line 1404, in lint_path
    self.lint_string(
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter.py", line 1186, in lint_string
    parsed = self.parse_string(in_str=in_str, fname=fname, config=config)
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/linter.py", line 874, in parse_string
    templated_file, templater_violations = self.templater.process(
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/templaters/dbt.py", line 188, in process
    return self._unsafe_process(fname, in_str, config)
  File "/usr/local/lib/python3.8/site-packages/sqlfluff/core/templaters/dbt.py", line 230, in _unsafe_process
    raise RuntimeError("File %s was not found in dbt project" % fname)
RuntimeError: File models/shared/ga_daily_sessions.sql was not found in dbt project

This error seems a little misleading. Additionally, I'm curious about the design decision to not lint dbt models that are disabled.

Expected Behaviour

For sqlfluff to be able to lint disabled models. Or at least have a more helpful error message.

Steps to Reproduce

Disable a dbt model and try to lint it.

Version

$ sqlfluff --version
sqlfluff, version 0.4.1

Configuration

[sqlfluff]
dialect = snowflake
templater = dbt
# dbt templating does not keep trailing new lines (L009)
exclude_rules = L007,L009,L031,L033,L034

[sqlfluff:rules]
max_line_length = 120
comma_style = trailing

[sqlfluff:rules:L010]
capitalisation_policy = upper
@dwallace0723 dwallace0723 added the bug Something isn't working label Apr 6, 2021
@alanmcruickshank
Copy link
Member

@dwallace0723 - I'm pretty sure in this case, a disabled model isn't compiled. The dbt templater uses the dbt compiler internally to process the file before linting. If it's never compiled then the templater won't be able to find it to lint it.

I'm tempted to say that the solution here is a clearer error message which says the user will either need to enable the model, or use a different templater. Using the basic jinja templater would also work, but would fail for any files which use any more advanced dbt syntax.

More advanced solutions would involve:

  • Falling back to the jinja templater if the dbt templater fails?
  • Hacking the dbt compiler to force enable a model in some way if it's specified directly?

@dmateusp , as the expert on the dbt templater, what do you think?

@dwallace0723
Copy link
Author

I'm tempted to say that the solution here is a clearer error message which says the user will either need to enable the model, or use a different templater.

@alanmcruickshank what are your thoughts on just skipping disabled dbt models and displaying a message saying the file/model was skipped or couldnt be found? dbt does something similar when trying to run disabled models:

dbt@1432a0e63563:/workspaces/dbt-dutchie$ dbt run --models ga_daily_sessions
Running with dbt=0.19.1
Found 330 models, 370 tests, 20 snapshots, 0 analyses, 440 macros, 1 operation, 0 seed files, 141 sources, 0 exposures
The selector 'ga_daily_sessions' does not match any nodes and will be ignored
WARNING: Nothing to do. Try checking your model configs and model specification args

@dmateusp
Copy link
Contributor

With the PR I opened, here's the new behavior:

🚀 sqlfluff lint models/my_new_project/disabled_model.sql
=== [dbt templater] Compiling dbt project...
WARNING    Skipped file models/my_new_project/disabled_model.sql because the model was disabled

dmateusp pushed a commit to dmateusp/sqlfluff that referenced this issue Apr 13, 2021
dmateusp pushed a commit that referenced this issue Apr 13, 2021
* Add an exception to skip files ⚠️

* Skip files on linting when they raise skip file exception 🔨

* Raise skip file exception in dbt templater when model is disabled

* Test all! ✨

* Add to CHANGELOG 🧐
@polmonso
Copy link

polmonso commented Feb 27, 2024

Can we silence the warning as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants