Skip to content
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

Merged
merged 17 commits into from
Oct 26, 2021

Conversation

kadero
Copy link
Contributor

@kadero kadero commented Sep 27, 2021

resolves #3874

Description

This PR aims to allow overriding the FreshnessThreshold params (error_after and warning_after).

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label Sep 27, 2021
@kadero kadero marked this pull request as draft September 27, 2021 06:41
@kadero kadero force-pushed the feature/nullable_error_after_in_sources branch from 81137e7 to 0e083be Compare September 27, 2021 07:12
@kadero
Copy link
Contributor Author

kadero commented Sep 27, 2021

Hello @jtcohen6 @lchoward 👋,

Here is a first proposition based on what we agreed on the initial issue.

For now, the changes reflect what we agreed here, and the tests were fixed naively.

Before going further and adding new tests (units and integrations), I would like your thought on the current implementation

Many thanks 🙏

@kadero kadero force-pushed the feature/nullable_error_after_in_sources branch from a571a94 to d61225a Compare October 2, 2021 07:43
@kadero kadero force-pushed the feature/nullable_error_after_in_sources branch from 4349176 to 3d3400f Compare October 5, 2021 08:16
@kadero kadero marked this pull request as ready for review October 5, 2021 08:24
@jtcohen6
Copy link
Contributor

jtcohen6 commented Oct 6, 2021

@kadero Thanks so much for the contribution! I do think it would be good to add at least one end-to-end test case in test/integration/042_sources_test/, wherein a child source table disables the error_after set by its parent source.

@leahwicz The logic in this PR follows an implementation I described over in #3874 (comment). I think it would be right to have an engineer from the Core team take a look, to make sure there isn't anything big that @kadero and I are both missing.

@leahwicz
Copy link
Contributor

leahwicz commented Oct 6, 2021

@gshank @nathaniel-may this falls into your domain so would you be able to take a look at this please and see what you think?

Copy link
Contributor

@nathaniel-may nathaniel-may left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python looks good to me and I only had one minor suggestion. I'm not deeply familiar with this corner of the code base yet so I'm going to withhold an explicit approval for now. Happy to do a more time consuming deep dive if we need to though.

core/dbt/parser/sources.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadero When you get a chance:

Thanks again for the contribution!

}
)

result_source_c = self.get_result_from_unique_id(data, 'source.test.test_source.source_c')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadero When you get a chance:

Thanks again for the contribution!

Hello @jtcohen6 @nathaniel-may 👋,

As we agreed, I created an integration test under test/integration/042_sources_test/, where a child source (called source_c) disables the error_after set by its parent source. 🙂

Unfortunately, the test didn't pass, everything goes on as if the child source inherit the error_after set by its parent 😕.

Do you have any clues, are we missing something?

Many thanks your support 🙏

result_source_c['criteria'],
{
'warn_after': {'count': 6, 'period': 'hour'},
'error_after': None,
Copy link
Contributor Author

@kadero kadero Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return 'error_after': {'count': 24, 'period': 'hour'} instead of 'error_after': None, 😕

)

result_source_c = self.get_result_from_unique_id(data, 'source.test.test_source.source_c')
self.assertEqual(result_source_c['status'], 'warn')
Copy link
Contributor Author

@kadero kadero Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the tests, and glad we caught the unexpected behavior! I think I see the place in the logic where that's occurring

if base and update:
return base.merged(update)
else:
return update or base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ✅ If base and update, merge them. This will apply if update is {}, too
  • ✅ If base is None, take update
  • ❌ If update is None (override!), we need to return None

So something like:

def merge_freshness_time_thresholds(
    base: Optional[Time], update: Optional[Time]
) -> Optional[Time]:
    if base and update:
        return base.merged(update)
    elif update is None:
        return None
    else:
        return update or base

Copy link
Contributor Author

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 ✔️

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @kadero! Thank you for the contribution :)

I just moved up the changelog entry, since we released v1.0.0b2 yesterday. As soon as the tests pass, I'll merge this in

@jtcohen6 jtcohen6 merged commit d2aa920 into dbt-labs:main Oct 26, 2021
jtcohen6 added a commit to dbt-labs/dbt-redshift that referenced this pull request Oct 27, 2021
jtcohen6 added a commit to dbt-labs/dbt-snowflake that referenced this pull request Oct 27, 2021
jtcohen6 added a commit to dbt-labs/dbt-bigquery that referenced this pull request Oct 27, 2021
jtcohen6 added a commit to dbt-labs/dbt-redshift that referenced this pull request Oct 27, 2021
jtcohen6 added a commit to dbt-labs/dbt-bigquery that referenced this pull request Oct 27, 2021
jtcohen6 added a commit to dbt-labs/dbt-snowflake that referenced this pull request Oct 27, 2021
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* Add nullable error after feature

* add merge_error_after method

* Fix FreshnessThreshold merged test

* Fix other tests

* Fix merge error after

* Fix test docs generate integration test

* Fix source integration test

* Typo and fix linting.

* Fix mypy test

* More terse way to express merge_freshness_time_thresholds

* Update Changelog.md

* Add integration test

* Fix conflict

* Fix contributing.md

* Fix integration tests

* Move up changelog entry

Co-authored-by: Jeremy Cohen <[email protected]>

automatic commit by git-black, original commits:
  d2aa920
siephen pushed a commit to AgencyPMG/dbt-bigquery that referenced this pull request May 16, 2022
abbywh pushed a commit to abbywh/dbt-redshift that referenced this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For source freshness, allow null error_after with non-null warning_after
4 participants