Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Unclear error message when a column in a contracted model is missing a data_type #707

Closed
dbeatty10 opened this issue Jan 26, 2024 · 3 comments
Labels
bug Something isn't working Stale

Comments

@dbeatty10
Copy link
Contributor

dbeatty10 commented Jan 26, 2024

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'

image

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

@dbeatty10 dbeatty10 added enhancement New feature or request triage labels Jan 26, 2024
@dbeatty10 dbeatty10 transferred this issue from dbt-labs/dbt-core Jan 26, 2024
@dbeatty10
Copy link
Contributor Author

dbeatty10 commented Jan 27, 2024

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:

{{ get_table_columns_and_constraints() }}
{{ get_assert_columns_equivalent(sql) }}

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])

@dbeatty10 dbeatty10 added bug Something isn't working and removed triage enhancement New feature or request labels Jan 27, 2024
@dbeatty10 dbeatty10 changed the title [Feature] Better error message when a column in a contracted model is missing a data_type [Bug] Unclear error message when a column in a contracted model is missing a data_type Jan 27, 2024
Copy link
Contributor

github-actions bot commented Aug 5, 2024

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Aug 5, 2024
Copy link
Contributor

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
1 participant