[Bug] Unclear error message when a column in a contracted model is missing a `data_type`
dbeatty10 opened this issue · comments
As originally reported in dbt-labs/dbt-core#8063 and dbt-labs/dbt-core#8070:
Originally posted by @yuna-tang in dbt-labs/dbt-core#8070 (comment)
Hi @jtcohen6, I find this post when we try to implement the contract configs for our models.
We are on dbt1.6, however, I see different error messages:
06:03:09 Completed with 1 error and 0 warnings:
06:03:09
06:03:09 'data_type'
We are using redshift and dbt1.6. I would prefer to see messages like below.
05:26:10 Running with dbt=1.6.5
05:26:10 Registered adapter: redshift=1.6.0
18:42:35 Compilation Error in model my_model (models/my_model.sql)
Contracted models require data_type to be defined for each column. Please ensure that the column name and data_type are defined within the YAML configuration for the ['tool'] column(s).
Reprex
Create project files as described in dbt-labs/dbt-core#8063.
Then run:
dbt seed && dbt run -s my_model
And get an error like this:
23:28:27 Unhandled error while executing
'data_type'
23:28:27 1 of 1 ERROR creating sql table model dbt_dbeatty_tools.my_model ............... [ERROR in 0.07s]
23:28:28
23:28:28 Finished running 1 table model in 0 hours 0 minutes and 3.88 seconds (3.88s).
23:28:28
23:28:28 Completed with 1 error and 0 warnings:
23:28:28
23:28:28 'data_type'
23:28:28
23:28:28 Done. PASS=0 WARN=0 ERROR=1 SKIP=0 TOTAL=1
There's a full stack trace within logs/dbt.log
, but it wasn't clear to me exactly where the true issue was.
Proposed solution
To match the order in dbt-postgres, dbt-bigquery, and dbt-snowflake, just flip the order of these two lines:
dbt-redshift/dbt/include/redshift/macros/adapters.sql
Lines 51 to 52 in f95c534
It's supposed to be this before this:
{{ get_assert_columns_equivalent(sql) }}
{{ get_table_columns_and_constraints() }}
Nice-to-have
Add some defensive code immediately above here to raise a helpful error message when the data_type
key is not defined:
if not v.get("data_type"):
raise ColumnTypeMissingError([col_name])