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

[CT-2814] [Feature] Better error message when a column in a contracted model is missing a data_type #8070

Closed
3 tasks done
Tracked by #7979
dbeatty10 opened this issue Jul 11, 2023 · 5 comments
Closed
3 tasks done
Tracked by #7979
Assignees
Milestone

Comments

@dbeatty10
Copy link
Contributor

dbeatty10 commented Jul 11, 2023

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

We didn't provide a helpful error message here which made it hard for the user to see what was going on:

Unhandled error while executing
'data_type'

We should provide a better error message. Maybe some like this:

You have an enforced contract for model X, but column Y is missing a specified data_type

Of course replace X and Y with the actual model / column names! 😎

The relevant area of code is somewhere around here:

rendered_column_constraint = [f"{col_name} {v['data_type']}"]

Describe alternatives you've considered

We could leave it as-is, but that wouldn't be the best 😢

Who will this benefit?

All of us that miss tiny little things and just need helpful direction of how to fix it.

Are you interested in contributing this feature?

No response

Anything else?

No response

@dbeatty10 dbeatty10 added enhancement New feature or request triage labels Jul 11, 2023
@github-actions github-actions bot changed the title [Feature] Better error message when a column in a contracted model is missing a `data_type [CT-2814] [Feature] Better error message when a column in a contracted model is missing a `data_type Jul 11, 2023
@MichelleArk
Copy link
Contributor

MichelleArk commented Jul 11, 2023

We should be able to raise the existing ColumnTypeMissingError exception (via column_type_missing) here. Currently it's raised right before creating an empty sql statement (to get the model contract based on the schema.yml file). This check could be moved further up the chain, either in jinja where we check that a model is contracted or potentially during parsing when we patch node properties.

Some related work: 746ca7d

@dbeatty10 dbeatty10 changed the title [CT-2814] [Feature] Better error message when a column in a contracted model is missing a `data_type [CT-2814] [Feature] Better error message when a column in a contracted model is missing a data_type Jul 11, 2023
@jtcohen6
Copy link
Contributor

potentially during parsing when we patch node properties

IIRC, we're not able to do this during parsing because it's possible that we're patching node properties (columns before we know whether the model is actually configured with contract: {enforced: true}. (That is, until/unless we do the work described in #6511.)

So this change makes sense to me:

This check could be moved further up the chain... in jinja where we check that a model is contracted

@emmyoop
Copy link
Member

emmyoop commented Aug 4, 2023

I believe this was done and released in 1.6 as part of commit 814eb65. Do we want to raise the error in another way?

@jtcohen6
Copy link
Contributor

jtcohen6 commented Aug 4, 2023

@emmyoop You're right!! Using the repro case from #8063:

18:42:35  1 of 1 START sql view model dbt_jcohen.my_model ................................ [RUN]
18:42:35  1 of 1 ERROR creating sql view model dbt_jcohen.my_model ....................... [ERROR in 0.08s]
18:42:35
18:42:35  Finished running 1 view model in 0 hours 0 minutes and 0.20 seconds (0.20s).
18:42:35
18:42:35  Completed with 1 error and 0 warnings:
18:42:35
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).

I think this one can be closed :)

@yuna-tang
Copy link

Hi @jtcohen6, I find this post when we try to implement the contract configs for our models.
We are on dbg1.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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants