sqlfluff: AttributeError: module 'dbt.flags' has no attribute 'PROFILES_DIR' with dbt 1.5
Search before asking
- I searched the issues and found no similar issues.
What Happened
After upgrading to dbt 1.5 and SQLFluff 2.1.0, I get the following error when I run sqlfluff lint:
AttributeError: module 'dbt.flags' has no attribute 'PROFILES_DIR'
Expected Behaviour
I don’t get this error on SQLFluff 2.0.7 with dbt 1.4.6.
Observed Behaviour
% sqlfluff lint
=== [dbt templater] Sorting Nodes...
file /Users/johnkennedy/Projects/maple-data/dbt/dbt_packages/audit_helper/integration_tests/analyses/compTraceback (most recent call last):
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/bin/sqlfluff", line 8, in <module>
sys.exit(cli())
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/sqlfluff/cli/commands.py", line 605, in lint
result = lnt.lint_paths(
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/sqlfluff/core/linter/linter.py", line 1206, in lint_paths
for i, linted_file in enumerate(runner.run(expanded_paths, fix), start=1):
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/sqlfluff/core/linter/runner.py", line 106, in run
for fname, partial in self.iter_partials(fnames, fix=fix):
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/sqlfluff/core/linter/runner.py", line 59, in iter_partials
for fname, rendered in self.iter_rendered(fnames):
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/sqlfluff/core/linter/runner.py", line 42, in iter_rendered
for fname in self.linter.templater.sequence_files(
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/sqlfluff_templater_dbt/templater.py", line 263, in sequence_files
self.profiles_dir = self._get_profiles_dir()
File "/Users/johnkennedy/.local/share/virtualenvs/dbt--3QRDvUu/lib/python3.10/site-packages/sqlfluff_templater_dbt/templater.py", line 196, in _get_profiles_dir
or flags.PROFILES_DIR
AttributeError: module 'dbt.flags' has no attribute 'PROFILES_DIR'
How to reproduce
- Upgrade dbt to 1.5
- Upgrade SQLFluff to 2.1.0
- Run
sqlfluff lint
Dialect
redshift
Version
sqlfluff - 2.1.0 sqlfluff-templater-dbt - 2.1.0 Python 3.10.11
Configuration
[sqlfluff] dialect = redshift templater = dbt
[sqlfluff:templater:dbt] apply_dbt_builtins = true profile = maple project_dir = dbt
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
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 12
- Comments: 17 (7 by maintainers)
The same error message is occurring again with
dbt1.8.0released today (usingsqlfluff3.0.6)I had troubles similar to this issue after a DBT upgrade. It seems like https://github.com/dbt-labs/dbt-core/issues/10135#issuecomment-2113728550 helped me resolve the issue, at least on my local machine (and the broken CI/github actions seem to be fixed too)
Quoting :
Our project uses poetry so I also re-ran a poetry install to make sure everything was right
fixed via https://github.com/sqlfluff/sqlfluff/pull/4886
Thanks, those instructions didn’t work for me (using
poetry), but the comments hinted at the fix - blowing away the virtual env and starting again sorted it for me.https://github.com/sqlfluff/sqlfluff/pull/4828 was possibly related but doesn’t appear to have resolved the issue affecting many here and in the comments there.
Also having this issue with Python 3.9.16 dbt-core==1.5.0 dbt-bigquery==1.5.1 sqlfluff-templater-dbt==2.0.7
I’m having the same issue, and these are my versions Python 3.11.0 dbt-core==1.5.0 dbt-bigquery==1.5.1 sqlfluff-templater-dbt==2.0.7
As a temporary workaround I added this to
.sqlfluff: