dbt_artifacts icon indicating copy to clipboard operation
dbt_artifacts copied to clipboard

[Bug]: Database Error ('22001', '[22001] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server] String or binary data would be truncated.

Open JustGitting opened this issue 4 months ago • 1 comments

Overview

I've installed dbt_artifacts according to the Quickstart guide in a Windows 10 / powershell environment.

After dbt run completes successfully, the following error appears:

> dbt run --select '+table1' 
01:50:41  Running with dbt=1.9.0
01:50:41  Registered adapter: sqlserver=1.9.0
01:50:44  Found 584 models, 1 operation, 236 data tests, 240 sources, 1133 macros
01:50:44  
01:50:44  Concurrency: 8 threads (target='dev')
01:50:44  
01:50:44  1 of 4 START sql table model ...
01:53:08  4 of 4 OK created sql table model ... [OK in 44.34s]
01:53:08  
01:53:08  Uploading model executions
01:53:08  Uploading seed executions
01:53:08  Uploading test executions
01:53:08  Uploading snapshot executions
01:53:08  Uploading exposures
01:53:08  Uploading seeds
01:53:08  Uploading snapshots
01:53:08  Uploading invocations
01:53:08  Uploading sources
01:53:09  
01:53:09  Exited because of keyboard interrupt
01:53:09
01:53:09  Done. PASS=4 WARN=0 ERROR=0 SKIP=0 TOTAL=4
01:53:09
01:53:09  Finished running 4 table models in 0 hours 2 minutes and 24.97 seconds (144.97s).
01:53:09  Encountered an error:
Database Error
  ('22001', '[22001] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]String or binary data would be truncated. (8152) (SQLExecDirectW); [22001] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The statement has been terminated. (3621)')

The following tables in the DB are empty.

exposures invocations model_executions models seed_executions seeds snapshot_executions snapshots sources test_executions tests

Turning on debugging (> dbt run --log-level debug --select '+table1') shows the problem occurs when loading the sources table with a massive json block:

...
03:14:43  SQL status: OK in 0.000 seconds
03:14:43  Uploading sources
03:14:43  Using sqlserver connection "master"
03:14:43  On master: /* {"app": "dbt", "dbt_version": "1.9.0", "profile_name": "my_analysis", "target_name": "dev", "connection_name": "master"} */


insert into "My-DB"."dbt".sources

	(
		command_invocation_id,
		node_id,
		run_started_at,
		 "database", "schema",

		source_name,
		loader,
		name,
		identifier,
		loaded_at_field,
		freshness,
		all_results
	)

	select
		"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"
	from ( values
	(
...
-- ~4000 rows
...
           )
        ) v ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")

03:14:44  fabric adapter: Database error: ('22001', '[22001] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]String or binary data would be truncated. (8152) (SQLExecDirectW); [22001] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The statement has been terminated. (3621)')
03:14:44  On master: Close
03:14:44
03:14:44  Exited because of keyboard interrupt
..

The sources table is defined as:

CREATE TABLE [My-DB].dbt.sources (
	command_invocation_id varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	node_id varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	run_started_at datetime2(6) NULL,
	[database] varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	[schema] varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	source_name varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	loader varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	name varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	identifier varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	loaded_at_field varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	freshness varchar(MAX) COLLATE Latin1_General_CI_AS NULL,
	all_results varchar(MAX) COLLATE Latin1_General_CI_AS NULL
);

How to reproduce

run the following command:

> dbt run

Expected behaviour

dbt_artifacts completes successfully.

Environment

Results of running dbt --version:

I'm using dbt 1.9 as sqlserver only supports 1.9 currently so I cannot upgrade.

> dbt --version
Core:
  - installed: 1.9.0
  - latest:    1.10.9 - Update available!

  Your version of dbt-core is out of date!
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

Plugins:
  - fabric:    1.9.3 - Update available!
  - sqlserver: 1.9.0 - Up to date!

  At least one plugin is out of date or incompatible with dbt-core.
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

Please paste the contents of your packages.yml file here:

packages:
  - package: dbt-labs/codegen
    version: 0.13.1
  - package: dbt-msft/tsql_utils
    version: 1.2.0
  - package: dbt-labs/dbt_utils
    version: 1.3.0
  - package: calogica/dbt_date
    version: 0.10.1
  - package: calogica/dbt_expectations
    version: 0.10.4
  - package: dbt-labs/audit_helper
    version: 0.12.1
  - package: brooklyn-data/dbt_artifacts
    version: 2.9.3

JustGitting avatar Aug 27 '25 03:08 JustGitting