-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Feature: nullable error_after in source #3955
Changes from all commits
383af7a
0e083be
3853704
c77c075
83732b8
ce617b0
51513d2
d61225a
3d3400f
0215e4f
610c7f6
ca82dd4
ea8210a
40b8950
8013cf3
14b6c69
0655c5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version: 2 | ||
sources: | ||
- name: test_source | ||
loader: custom | ||
freshness: # default freshness | ||
warn_after: {count: 12, period: hour} | ||
error_after: {count: 24, period: hour} | ||
schema: "{{ var(env_var('DBT_TEST_SCHEMA_NAME_VARIABLE')) }}" | ||
loaded_at_field: loaded_at | ||
quoting: | ||
identifier: True | ||
tags: | ||
- my_test_source_tag | ||
tables: | ||
- name: source_a | ||
identifier: source | ||
loaded_at_field: "{{ var('test_loaded_at') | as_text }}" | ||
freshness: | ||
warn_after: {count: 6, period: hour} | ||
# use the default error_after defined above | ||
- name: source_b | ||
identifier: source | ||
loaded_at_field: "{{ var('test_loaded_at') | as_text }}" | ||
freshness: | ||
warn_after: {count: 6, period: hour} | ||
error_after: {} # use the default error_after defined above | ||
- name: source_c | ||
identifier: source | ||
loaded_at_field: "{{ var('test_loaded_at') | as_text }}" | ||
freshness: | ||
warn_after: {count: 6, period: hour} | ||
error_after: null # override: disable error_after for this table | ||
- name: source_d | ||
identifier: source | ||
loaded_at_field: "{{ var('test_loaded_at') | as_text }}" | ||
freshness: | ||
warn_after: {count: 6, period: hour} | ||
error_after: {count: 72, period: hour} # override: use this new behavior instead of error_after defined above | ||
- name: source_e | ||
identifier: source | ||
loaded_at_field: "{{ var('test_loaded_at') | as_text }}" | ||
freshness: null # override: disable freshness for this table |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ def test_postgres_basic_source_def(self): | |
['expected_multi_source', 'multi_source_model']) | ||
results = self.run_dbt_with_vars(['test']) | ||
self.assertEqual(len(results), 6) | ||
print(results) | ||
|
||
@use_profile('postgres') | ||
def test_postgres_source_selector(self): | ||
|
@@ -400,6 +401,81 @@ def test_postgres_source_freshness_selection_graph_operation(self): | |
self.assertEqual(results[0].status, 'pass') | ||
self._assert_freshness_results('target/ancestor_source.json', 'pass') | ||
|
||
class TestOverrideSourceFreshness(SuccessfulSourcesTest): | ||
|
||
@property | ||
def models(self): | ||
return "override_freshness_models" | ||
|
||
@staticmethod | ||
def get_result_from_unique_id(data, unique_id): | ||
try: | ||
return list(filter(lambda x : x['unique_id'] == unique_id, data['results']))[0] | ||
except IndexError: | ||
raise f"No result for the given unique_id. unique_id={unique_id}" | ||
|
||
def _run_override_source_freshness(self): | ||
self._set_updated_at_to(timedelta(hours=-30)) | ||
self.freshness_start_time = datetime.utcnow() | ||
|
||
path = 'target/pass_source.json' | ||
results = self.run_dbt_with_vars( | ||
['source', 'freshness', '-o', path], | ||
expect_pass=False | ||
) | ||
self.assertEqual(len(results), 4) # freshness disabled for source_e | ||
|
||
self.assertTrue(os.path.exists(path)) | ||
with open(path) as fp: | ||
data = json.load(fp) | ||
|
||
result_source_a = self.get_result_from_unique_id(data, 'source.test.test_source.source_a') | ||
self.assertEqual(result_source_a['status'], 'error') | ||
self.assertEqual( | ||
result_source_a['criteria'], | ||
{ | ||
'warn_after': {'count': 6, 'period': 'hour'}, | ||
'error_after': {'count': 24, 'period': 'hour'}, | ||
'filter': None | ||
} | ||
) | ||
|
||
result_source_b = self.get_result_from_unique_id(data, 'source.test.test_source.source_b') | ||
self.assertEqual(result_source_b['status'], 'error') | ||
self.assertEqual( | ||
result_source_b['criteria'], | ||
{ | ||
'warn_after': {'count': 6, 'period': 'hour'}, | ||
'error_after': {'count': 24, 'period': 'hour'}, | ||
'filter': None | ||
} | ||
) | ||
|
||
result_source_c = self.get_result_from_unique_id(data, 'source.test.test_source.source_c') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hello @jtcohen6 @nathaniel-may 👋, As we agreed, I created an integration test under Unfortunately, the test didn't pass, everything goes on as if the child source inherit the Do you have any clues, are we missing something? Many thanks your support 🙏 |
||
self.assertEqual(result_source_c['status'], 'warn') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return |
||
self.assertEqual( | ||
result_source_c['criteria'], | ||
{ | ||
'warn_after': {'count': 6, 'period': 'hour'}, | ||
'error_after': None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return |
||
'filter': None | ||
} | ||
) | ||
|
||
result_source_d = self.get_result_from_unique_id(data, 'source.test.test_source.source_d') | ||
self.assertEqual(result_source_d['status'], 'warn') | ||
self.assertEqual( | ||
result_source_d['criteria'], | ||
{ | ||
'warn_after': {'count': 6, 'period': 'hour'}, | ||
'error_after': {'count': 72, 'period': 'hour'}, | ||
'filter': None | ||
} | ||
) | ||
|
||
@use_profile('postgres') | ||
def test_postgres_override_source_freshness(self): | ||
self._run_override_source_freshness() | ||
|
||
class TestSourceFreshnessErrors(SuccessfulSourcesTest): | ||
@property | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base
andupdate
, merge them. This will apply ifupdate
is{}
, toobase
isNone
, takeupdate
update
isNone
(override!), we need to returnNone
So something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed 🙈,
Thanks @jtcohen6, update done and the test is fixed ✔️