Skip to content

Commit

Permalink
Update code example for fail_calc (#5221)
Browse files Browse the repository at this point in the history
## What are you changing in this pull request and why?

The current code example does not always work and may raise an error
like this:

```
14:01:53  None is not of type 'integer'
14:01:53  
14:01:53  Failed validating 'type' in schema['properties']['failures']:
14:01:53      {'type': 'integer'}
14:01:53  
14:01:53  On instance['failures']:
14:01:53      None
```

As described in dbt-labs/dbt-core#4248, it's
known that:
- tests whose `fail_calc` is a sum() function raises an error when the
test produces no rows at all

Well, that explains why the code example doesn't work!

Jerco described two options for dealing with this:

1. rewrite the test query, to ensure it always returns at least one row
1. rewrite the `fail_calc`, to handle the case in which no rows are
returned

This PR adopts the 2nd option and updates the code example to handle the
case in which no rows are returned.

## 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.
- [x] I've verified that the updated code example works
  • Loading branch information
nghi-ly authored Apr 3, 2024
2 parents c25a791 + 307841e commit 017526f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion website/docs/reference/resource-configs/fail_calc.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ models:
tests:
- unique:
config:
fail_calc: "sum(n_records)"
fail_calc: "case when count(*) > 0 then sum(n_records) else 0 end"
```
</File>
Expand Down

0 comments on commit 017526f

Please sign in to comment.