-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Model Contract Alters Numeric Precision #10430
Comments
Thanks for reaching out about this @dbernett-amplify ! I was able to to reproduce the same error messages as you -- see below for the simple project files I used.
|
[Preview](https://docs-getdbt-com-git-dbeatty10-patch-1-dbt-labs.vercel.app/reference/resource-configs/contract) ## What are you changing in this pull request and why? The [`contracts`](https://docs.getdbt.com/reference/resource-configs/contract#example) page includes some important information as it relates to size, precision, and scale when enforcing contracts, but it's hard to pick out visually. I want to be send hyperlinks to folks that points to just the right section. For example, in this issue: dbt-labs/dbt-core#10430. ## Checklist - [x] Review the [Content style guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md) so my content adheres to these guidelines.
@dbeatty10 thanks! I appreciate your help here. One thing worth calling out is that the docs say:
That's actually not true. It doesn't fail contract enforcement. If your specification in the contract doesn't match what's actually in the column, then it just coerces your data to whatever the contract says. Which in many ways is a bigger deal because that happens silently. So probably worth calling that out in the docs? I'd also suggest swapping the order of the two paragraphs in that section so that you're telling people first about all the stuff they DO have to worry about and second about what they don't have to worry about. Otherwise, people might stop after the first sentence or two and assume that the gist of the section is that precision, scale, etc. don't matter. |
@dbeatty10 and then I guess one other follow up thought I have is that it feels a little inconsistent that if you specify just "number" as the |
@dbeatty10 also wanted to follow up with another slightly different issue.
So if you specify a different precision in the contract from what snowflake would infer from the data, it will coerce the data to your specified prevision on the full-refresh, but on the subsequent incremental build it will not coerce it, and will throw an error (if you've set So basically to make an incremental model with
To be honest, that feels like a lot of work. So would be great if that could change. But if not, then that should at least be called out in the docs. Thanks again for your help! |
Is this a new bug in dbt-core?
Current Behavior
I have a column that is explicitly defined as number(3,1) in my upstream model.
I select that column in my incremental model.
My incremental models specifies
on_schema_change = 'fail'
.My incremental has a contract that defines the
data_type
for that column as "number".If that incremental model has the contract disabled...
If that incremental model has the contract enabled...
on_schema_change
yells about the column type having changed to number(3,1) and the model fails.We have observed this behavior in several different models recently.
Eventually, I realized that I need to explicitly specify "number(3,1)" as the data_type in the contract in order to get it to come out as number(3,1) on that initial full-refresh, and to then not break on the subsequent incremental build, but it feels non-obvious that just specifying "number" as the data type in the contract is going to change the precision from whatever dbt would otherwise make it to (38,0).
On a related note, it would be helpful if the documentation specified what the allowed values are for the
data_type
argument in a contract. I often feel like I'm guessing at what it wants.Expected Behavior
I would expect that dbt will make the precision whatever it should be according to the sql, and that a contract that specifies "number" as the
data_type
will just check that the data is in fact some type of number. Not that the contract will actually change the data type.It's also worth noting that if I mis-specify the column in the contract as "number(2,0)", it does not throw an error. It just changes the column to number(2,0) and I lose my decimal. Again, I would expect that the contract is just describing the data types specified in the sql and that if they mismatch, I'll see an error, not that the contract is actually changing the data types from what they are according to the sql.
Steps To Reproduce
I'm working in the Cloud IDE running dbt 1.7 and using Snowflake.
Relevant log output
No response
Environment
Which database adapter are you using with dbt?
snowflake
Additional Context
No response
The text was updated successfully, but these errors were encountered: