-
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
Add selected_resources
to the Jinja context
#5001
Add selected_resources
to the Jinja context
#5001
Conversation
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
core/dbt/context/base.py
Outdated
@@ -556,6 +557,15 @@ def flags(self) -> Any: | |||
""" | |||
return flags | |||
|
|||
@contextproperty | |||
def selected_resources(self) -> Any: |
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.
I'm pretty sure that the base context is the wrong context for this functionality. We don't need this in yaml rendering and other non-sql rendering. It probably ought to go in a provider context. Is there some reason that you put it in base?
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.
I put it in Base because I looked at howflags
were configured and replicated some of the logic for selected_resources
, but I get your point and it makes much more sense to be in another context. I will update the code.
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.
I have just moved it to the ProviderContext
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.
Looks like you need to update the tests. In test_context.py you need to add 'selected_resources' to REQUIRED_MACRO_KEYS.
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.
LGTM with one nitpicking item for tests. I feel like this is ready to go once other tests are fixed.
@@ -0,0 +1,35 @@ | |||
on_run_start_macro_assert_selected_models_expected_list = """ | |||
{% macro assert_selected_models_expected_list(expected_list) %} |
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.
Really like the way you use this macro to test the functionality!
[ | ||
"build", | ||
"--select", | ||
"model1+", |
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.
Should we do a model2+
as one of the test cases? since the result of this selection is the same as the no select specified test below.
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.
I just modified a test to be model2+
It was failing at first (because model1
was not built) so I moved all the tests to a Class that uses the fixture build_all
, meaning that a full dbt build
is run before each test (which allows us to select nodes that are depending on other ones)
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.
LGTM! Left one question but not a blocker
@@ -0,0 +1,9 @@ | |||
kind: Features | |||
body: Add a variable called selected_resources in the Jinja context containing a list |
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.
@gshank could there be situations where selected_resources
is referenced before it got set by get_graph_queue
? I think there isn't but want to double-check.
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.
I think the selected_resources will be empty unless it's execution time, which should be okay. I suppose the list could be really big for a run command that executes the whole project, but I think that should be okay too; it doesn't do much except reference the list of nodes.
* Bumping version to 1.1.0rc1 * Updating requirements to latest release branch * Bumping manifest schema in tests * Fix unit test per dbt-labs/dbt-core#5001 Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com> Co-authored-by: leahwicz <60146280+leahwicz@users.noreply.github.com> Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
* Bumping version to 1.2.0a1 * Bumping schema version in tests * Try skipping test-build if alpha version * try this * i meant this * Fix unit test per dbt-labs/dbt-core#5001 * One less change than needed Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com> Co-authored-by: leahwicz <60146280+leahwicz@users.noreply.github.com>
* Add selected_resources in the Jinja context * Add tests for the Jinja variable selected_resources * Add Changie entry for the addition of selected_resources * Move variable to the ProviderContext * Move selected_resources from ModelContext to ProviderContext * Update unit tests for context to cater for the new selected_resources variable * Move tests to a Class where tests are run after a dbt build
* Add selected_resources in the Jinja context * Add tests for the Jinja variable selected_resources * Add Changie entry for the addition of selected_resources * Move variable to the ProviderContext * Move selected_resources from ModelContext to ProviderContext * Update unit tests for context to cater for the new selected_resources variable * Move tests to a Class where tests are run after a dbt build
* Bumping version to 1.2.0a1 * Bumping schema version in tests * Try skipping test-build if alpha version * try this * i meant this * Fix unit test per dbt-labs/dbt-core#5001 * One less change than needed Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com> Co-authored-by: leahwicz <60146280+leahwicz@users.noreply.github.com>
resolves #3471
Description
I don't know if I followed the correct approach but this code is adding a variable called
selected_resources
to the Jinja context. This is a list of all models/tests/snapshots etc... captured by the selectors for the dbt run. I checked howflags
were added to the context and did the same forselected_resources
, hence why it is under thecore/dbt
folder.The issue #3471 also mentions making this available for
run-operation
but this will be taken care of in another issue.My testing approach is to use a
on-run-start
hook to compare the value ofselected_resources
with the expected one.If this is merged the docs will need to be updated to mention the new variable and highlight that similar to
graph
is will only contain some information atexecute
time.Checklist