Skip to content

dbt doesn't properly return error message on wrong syntax #139

@dataders

Description

@dataders

re-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

  1. configure a target of type=sqlserver
  2. install dbt-sqlserver==0.19.1
  3. create a model (repro.sql) with intentionally wrong sql
    -- models/repro.sql
    -- notice the 'x' after "SELECT"
    SELECTx 1 as col_name
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions