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

Call adapter.pre_model_hook + adapter.post_model_hook within tests #10258

Merged
merged 12 commits into from
Jun 14, 2024

Conversation

McKnight-42
Copy link
Contributor

@McKnight-42 McKnight-42 commented Jun 3, 2024

resolves #10198

Problem

Allow tests to take in pre and post hooks similar to our pre/post_model_hook to take in configs like snowflake_warehouse and other arbitrary configs.

Solution

Potential Solutions:

  1. Update unit and data test execute methods to trigger either the existing pre/post_model_hoook and add logging to
    adapter definitions as described or in the area right after we add the hooks in via this pr.
  2. Create a new pre/post_test_hook in BaseAdapter in dbt-adapters then have the adapters create their own version of the method as we do for pre_model_hook (logging could possibly happen in method more easily this way) but would also mean many more pr's across adapters to add the new methods.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • 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
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@McKnight-42 McKnight-42 added the Skip Changelog Skips GHA to check for changelog file label Jun 3, 2024
@McKnight-42 McKnight-42 self-assigned this Jun 3, 2024
@cla-bot cla-bot bot added the cla:yes label Jun 3, 2024
Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.72%. Comparing base (d4a6482) to head (fa98fbd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10258      +/-   ##
==========================================
- Coverage   88.74%   88.72%   -0.02%     
==========================================
  Files         180      180              
  Lines       22483    22488       +5     
==========================================
  Hits        19953    19953              
- Misses       2530     2535       +5     
Flag Coverage Δ
integration 86.02% <100.00%> (-0.06%) ⬇️
unit 61.77% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@McKnight-42 McKnight-42 changed the title init push for issue 10198 Call adapter.pre_model_hook + adapter.post_model_hook within Jun 4, 2024
@McKnight-42 McKnight-42 changed the title Call adapter.pre_model_hook + adapter.post_model_hook within Call adapter.pre_model_hook + adapter.post_model_hook within tests Jun 4, 2024
@McKnight-42 McKnight-42 marked this pull request as ready for review June 6, 2024 15:58
@McKnight-42 McKnight-42 requested a review from a team as a code owner June 6, 2024 15:58
core/dbt/task/test.py Outdated Show resolved Hide resolved
core/dbt/task/test.py Outdated Show resolved Hide resolved
# execute materialization macro
macro_func()
finally:
self.adapter.post_model_hook(context, hook_ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

To confirm, this is not a behaviour change because:

cc @jtcohen6

Copy link
Contributor Author

@McKnight-42 McKnight-42 Jun 13, 2024

Choose a reason for hiding this comment

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

I think i can help supply a answer here. with this pr and

as tested in dbt-labs/dbt-snowflake#1070

Copy link
Contributor

Choose a reason for hiding this comment

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

ah! gotcha -- so configs were not possible to provide for generic tests in the past, which means there should not be any currently set on them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from my understanding yes, we could use a old pattern to set a set number of accepted configs linked in the generic_config issue, making this update to the newer syntax while maintaining the old will allow us to do this now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @MichelleArk @McKnight-42 for thinking of this!

As I see it, the only way in which this could be a "breaking" change is if someone had configured a singular test, or all tests (from dbt_project.yml), with a snowflake_warehouse that they didn't actually want to be used.

Something like:

# dbt_project.yml
tests:
  +snowflake_warehouse: does_not_exist
-- tests/my_singular_test.sql
{{ config(snowflake_warehouse = 'wrong_warehouse') }}

select ...

I do not see that as a breaking change; I see it as this feature in dbt (specifically dbt-snowflake) finally working as intended. As such, I do not believe we need to put it behind a legacy behavior migration flag.

@McKnight-42 McKnight-42 merged commit 27b2f96 into main Jun 14, 2024
63 checks passed
@McKnight-42 McKnight-42 deleted the mcknight/10198 branch June 14, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Skip Changelog Skips GHA to check for changelog file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Impl] Call adapter.pre_model_hook + adapter.post_model_hook within TestTask
5 participants