question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dbt doesn't properly return error message on wrong syntax

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
jeroen-mostertcommented, Jun 14, 2021

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.

1reaction
dataderscommented, Jun 22, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging errors - dbt Developer Hub
To fix this: Open the offending file (e.g. schema.yml ); Check the line in the error message (e.g. line 5 ); Find the...
Read more >
What happens if the SQL in my query is bad or I get a ...
If there's a mistake in your SQL, dbt will return the error that your database returns. $ dbt run --select customers. Running with...
Read more >
Exit codes | dbt Developer Hub
When dbt exits, it will return an exit code of either 0, 1, or 2. ... one handled error (eg. model syntax error,...
Read more >
exceptions - dbt Developer Hub
The exceptions namespace can be used to raise warnings and errors in dbt userspace.
Read more >
Tests - dbt Developer Hub
dbt CLI: Open the file path returned as part of the error message. Navigate to the target/compiled/schema_tests directory for all compiled test ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found