dbt doesn't properly return error message on wrong syntax
See original GitHub issuere-phrase of: #135
using dbt-sqlserver==0.19.1
, if you make a syntax error in a model, the dbt CLI does not return the error message like it used to in dbt-sqlserver<0.19.1
.
This has me stumped so I’m tagging all the folks who know more about TSQL than me: @NandanHegde15 @mikaelene @semcha @panasenco
steps to reproduce
- configure a target of
type=sqlserver
- install dbt-sqlserver==0.19.1
- create a model (
repro.sql
) with intentionally wrong sql-- models/repro.sql -- notice the 'x' after "SELECT" SELECTx 1 as col_name
- run the new model
dbt run -m repro
(dbt) anders.swanson@AMAC02FG0TMMD6R SalesOps % dbt run -m repro Running with dbt=0.19.1 Found 21 models, 46 tests, 0 snapshots, 0 analyses, 712 macros, 0 operations, 1 seed file, 24 sources, 1 exposure 16:07:15 | Concurrency: 1 threads (target='dev') 16:07:15 | 16:07:15 | 1 of 1 START view model ajs.repro.................................... [RUN] 16:07:16 | 1 of 1 OK created view model ajs.repro............................... [OK in 1.27s] 16:07:16 | 16:07:16 | Finished running 1 view model in 8.44s. Completed successfully Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1
more info
in the full extract of the dbt log you can see this query batch get executed
USE [dbt-msft-serverless-db];
execute(
'create view "test"."repro__dbt_tmp" as
SELECTx 1 as col_name'
);
Executing the above query batch directly against the database provides the following error message, that isn’t returned by dbt.
Msg 102, Level 15, State 1, Procedure demo__dbt_tmp, Line 2
Incorrect syntax near 'SELECTx'.
Interestingly enough, looking at the db’s logs, it does show the error/failure.
<batch_information><failure_reason>Err 102, Level 15, Server dbt-msft-server
Incorrect syntax near 'SELECTx'.</failure_reason></batch_information>
original motivation for change
The whole reason for this change is that if you try the below query, the error message, is 'CREATE VIEW' must be the first statement in a query batch
. This is why the CREATE VIEW
was wrapped in an EXEC
.
USE [dbt-msft-serverless-db]
CREATE VIEW dbo.view_test AS (
SELECT 1 as col_name
)
version info
dbt --version
installed version: 0.19.1
latest version: 0.19.1
Up to date!
Plugins:
- sqlserver: 0.19.1
- synapse: 0.19.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
I’ll just leave this commit here because I was unsure if it was clean enough for a PR (or if it belongs on this level, or further upstream in dbt itself), but I encountered this particular problem when we homebrewed support for multiple DBs – the root of the issue (at least with our change) was that you must process all result sets explicitly if a batch has more than one statement, otherwise you won’t get error notifications for anything but the first statement. I have not verified if this is the exact same issue or if my change fixes it, but it does look awfully familiar.
@mikaelene it was just an inane error about the Azure CLI not being able to installed. It completed now, so I’m going to merge it.