dbt-expectations: --store-failures with query context
Hi!
I have question / suggestion regarding behaviour of --store-failures
when used together with dbt-expectations.
We are looking to use dbt-expectations, but we are lacking some traceability features.
Let’s look at this meaningless column level assertion / test (from https://github.com/dbt-labs/jaffle_shop):
- name: orders
columns:
- name: order_id
tests:
- unique
- not_null
- dbt_expectations.expect_column_values_to_be_between:
min_value: 10
max_value: 40
When dbt is run with --store-failures
, single boolean column will be created in the persistent storage. To make this data source of truth and actionable, we want to add context or details to the results of the query. For example:
- name: orders
columns:
- name: order_id
tests:
- unique
- not_null
- dbt_expectations.expect_column_values_to_be_between:
query_context: 'order_id, customer_id, order_date, status'
min_value: 10
max_value: 40
This can be archived with simple changes to the macros. You can see example here:
This way, result table can have more context and details (row-level, in some cases), which might be useful not just for us.

Would love to get some feedback feasibility of this. We are happy to create PR from our side.
This is possible to implement without breaking any of the existing tests for current users.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 9
- Comments: 18 (5 by maintainers)
Hi guys, Just wondering if these changes were going forward. It would be really useful to have this 😃
Hi @artemboiko1 - sorry, haven’t had a ton of time to look into this. However, one thought I had was that rather than adding a
query_context
parameter to every test, I’d probably prefer we follow something similar to the dbt-core model and simplyselect *
) for non-grouped tests, orThis would still require going through all tests to make sure this works as intended. Also, I wouldn’t know how to test this in the integration_tests suite. Any ideas?
Wow I have just spent the last two days trying to figure out how to do just this!
I ended up overriding the dbt_expectations tests with slightly modified versions that accepted a contextual_column_list param. I then added a loop in the set expression to write this columns out with a max aggregation.
This allows me trace much more about test runs.
I’d like to get the start time, end time and invocation id of the run stored so that I could see how tests have behaved over multiple runs.
I’d also like to change the audit table naming convention so I don’t have to check all audit tables. Ideally the logs would all go in one table with the test name as column.
I’ll keep an eye on this ticket and may be able to help if needed.
That order of pull requests works for me. Although 3. should also be followed by a check of the integration_tests, right? In any case, I would want to release all of these as version
0.60
since it’s a potentially breaking change.@clausherther
dbt-core schema assertions already select
*
as the context for the failure, example:for this model
so the issue is dbt-expectations-specific