Skip to content

Commit

Permalink
Fix store_failures modifier for unique, not_null (dbt-labs#3577)
Browse files Browse the repository at this point in the history
* Fix store_failures modifier for unique, not_null

* Add test, changelog
  • Loading branch information
jtcohen6 authored Jul 16, 2021
1 parent 1f6386d commit 0ae93c7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Contributors:
- [@JLDLaughlin](https://github.com/JLDLaughlin) ([#3473](https://github.com/fishtown-analytics/dbt/pull/3473))
- [@jmriego](https://github.com/jmriego) ([#3526](https://github.com/dbt-labs/dbt/pull/3526))


## dbt 0.20.1 (Release TBD)

### Fixes
- Fix `store_failures` config when defined as a modifier for `unique` and `not_null` tests ([#3575](https://github.com/fishtown-analytics/dbt/issues/3575), [#3577](https://github.com/fishtown-analytics/dbt/pull/3577))


## dbt 0.20.0 (July 12, 2021)

### Fixes
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ def render_test_update(self, node, config, builder):
if builder.fail_calc is not None:
node.unrendered_config['fail_calc'] = builder.fail_calc
node.config['fail_calc'] = builder.fail_calc
if builder.store_failures is not None:
node.unrendered_config['store_failures'] = builder.store_failures
node.config['store_failures'] = builder.store_failures
# source node tests are processed at patch_source time
if isinstance(builder.target, UnpatchedSourceDefinition):
sources = [builder.target.fqn[-2], builder.target.fqn[-1]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ models:
columns:
- name: id
tests:
- unique
- unique:
store_failures: true
- not_null
- name: first_name
tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ def project_config(self):

def column_type_overrides(self):
return {}

def run_tests_store_one_failure(self):
test_audit_schema = self.unique_schema() + "_dbt_test__audit"

self.run_dbt(["seed"])
self.run_dbt(["run"])
self.run_dbt(["test"], expect_pass=False)

# one test is configured with store_failures: true, make sure it worked
self.assertTablesEqual("unique_problematic_model_id", "expected_unique_problematic_model_id", test_audit_schema)

def run_tests_store_failures_and_assert(self):
test_audit_schema = self.unique_schema() + "_dbt_test__audit"

self.run_dbt(["seed"])
self.run_dbt(["run"])
# make sure this works idempotently
# make sure this works idempotently for all tests
self.run_dbt(["test", "--store-failures"], expect_pass=False)
results = self.run_dbt(["test", "--store-failures"], expect_pass=False)

Expand Down Expand Up @@ -71,6 +81,7 @@ def column_type_overrides(self):

@use_profile('postgres')
def test__postgres__store_and_assert(self):
self.run_tests_store_one_failure()
self.run_tests_store_failures_and_assert()

class RedshiftTestStoreTestFailures(TestStoreTestFailures):
Expand Down

0 comments on commit 0ae93c7

Please sign in to comment.