-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Vscode saving sql file always results in error with dbt templater #105
Comments
Have you tried setting You could also check the output tab - sqlfluff channel (next to the terminal tab). That will give you the sqlfluff commands that run, you can use that to grab the format command that is running. Copy that command and try running it in your terminal, if the command still doesn't work in your terminal it might be an issue with sqlfluff and not this extension. |
Thanks @RobertOstermann , that fixed the issue for me. |
@RobertOstermann , I jumped to conclusions but this introduces a new issue when I enable this experimental feature. With {
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin",
"sqlfluff.executablePath": "${workspaceFolder}/venv/bin/sqlfluff",
"sqlfluff.dialect": "postgres",
"sqlfluff.linter.run": "onSave",
"sqlfluff.format.enabled": true,
"sqlfluff.experimental.format.executeInTerminal": true,
"files.associations": {
"*.sql": "jinja-sql",
"*.md": "markdown",
"*.yaml": "jinja-yaml",
"*.yml": "jinja-yaml",
},
"editor.formatOnSave": true
} I can modify some of the column names, but as soon as I save it my changes are undone and it is reverted to the previous version. So then I decided to remove {
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin",
"sqlfluff.executablePath": "${workspaceFolder}/venv/bin/sqlfluff",
"sqlfluff.dialect": "postgres",
"sqlfluff.linter.run": "onSave",
"sqlfluff.format.enabled": true,
"sqlfluff.experimental.format.executeInTerminal": true,
"files.associations": {
"*.sql": "jinja-sql",
"*.md": "markdown",
"*.yaml": "jinja-yaml",
"*.yml": "jinja-yaml",
}
} Now when I save my file it is linted as I would expect when I save my file, but it is not corrected by a TLDRUsing the experimental feature |
@FrankTub Could you check the output tab - sqlfluff channel (next to the terminal tab)? That will give you the sqlfluff commands that are being run by this extension. You can use that to grab the format command that is running. Copy that command and try running it in your terminal, if the command still doesn't work in your terminal it might be an issue with sqlfluff and not this extension. Also worth noting, I think that if you make any changes while the formatting is occurring you might run into issues as mentioned, is the formatting still not working if you do not change the file contents while the formatting is occurring? |
@RobertOstermann , I've made sure that I don't make any changes to my files while it is formatting. I tried to add it once more to my I've tried to check the output in the output tab of vscode, however I don't see any sqlfluff commands printed there. This is what I see: Is this the correct location where I could find the sqlfluff command that is run in the terminal? |
@FrankTub That is the correct output tab, but you have to change the channel to see the SQLFluff commands. It should be on the right side of the panel |
@RobertOstermann, aah never knew how that worked. I did some testing with my {
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin",
"sqlfluff.executablePath": "${workspaceFolder}/venv/bin/sqlfluff",
"sqlfluff.dialect": "postgres",
"sqlfluff.linter.run": "onSave",
"sqlfluff.format.enabled": true,
"sqlfluff.experimental.format.executeInTerminal": true,
"files.associations": {
"*.sql": "jinja-sql",
"*.md": "markdown",
"*.yaml": "jinja-yaml",
"*.yml": "jinja-yaml",
},
"editor.formatOnSave": true
} Created a new select
customer_organization_id,
vendor_organization_id
from {{ ref('lease_contracts') }}
This was saved correctly. Then I tried to modify my file to: select
customer_organization_id,
vendor_organization_id,
{{ current_timestamp() }} as dbt_created_at
from {{ ref('lease_contracts') }}
However when I press save it is changed back to what it was, ie: select
customer_organization_id,
vendor_organization_id
from {{ ref('lease_contracts') }}
In the Output tab of Vscode I can find:
So the statement that is logged is Then I ran below command in my terminal: (venv) .. data-warehouse-etl-dbt % /Users/frank.tubbing/source/repos/data-warehouse-etl-dbt/venv/bin/sqlfluff fix --force --dialect postgres models/test.sql
==== finding fixable violations ====
FORCE MODE: Attempting fixes...
=== [dbt templater] Sorting Nodes...
07:17:02 Registered adapter: postgres=1.5.2
=== [dbt templater] Compiling dbt project...
=== [dbt templater] Project Compiled.
==== no fixable linting violations found ====
All Finished 📜 🎉! Now my file is still as I would expect it to be, namely: select
customer_organization_id,
vendor_organization_id,
{{ current_timestamp() }} as dbt_created_at
from {{ ref('lease_contracts') }} So my guess is that this is some weird behavior of the SQLFluff plugin in Vscode. |
@FrankTub Does the extension work when you have |
@RobertOstermann , when we set |
@FrankTub Unfortunately that is currently the only way for the extension to work with DBT at the moment. I will take another look and see if I can improve the way the |
I'm using vscode and SQLFluff to work on my dbt-core project. I'm using the latest versions available at the moment.
And also for the SQLFluff version:
My
.vscode/settings.json
looks as below:When I try to save a very simple SQL model like below I receive an error pop-up in vscode. The sql file:
And the error:
At the top of my sql file the following code is inserted by saving the model:
�[0m15:10:19 Registered adapter: postgres=1.5.2
.Whatever I try, it seems impossible to save the model without receiving this error. If you try to save a new model it (sometimes) states something like
dbt templater fails silently, try dbt compile to verify
if you hover over the error in your file very quickly. However when I rundbt compile
this runs without errors.Any help would be highly appreciated.
The text was updated successfully, but these errors were encountered: