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

[#3885] Handle env_vars in partial parsing of SQL files #4101

Merged
merged 2 commits into from
Oct 26, 2021
Merged

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Oct 20, 2021

resolves #3885

Description

This code collects the env_vars from contexts that inherit from ProviderContext (SQL files), stores the env_var values in the manifest, and in the partial parsing code schedules the files with changed env_vars for parsing.

In addition, this makes the function names that generate contexts consistent (generate_[name]_context) and changes the 'created_at' field in various nodes to a float (time.time()) instead of int for more precision, because it was needed in a test case. Also removed some unnecessary code from the schema parser that handled pre-v2 configs.

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

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.

In basic local testing, this works wonderfully for .sql files. I left one comment around handling secret-prefixed env vars.

I'm really excited to extend this to .yml files, and eventually to work with var() as well as env_var().

@@ -790,3 +798,28 @@ def remove_source_override_target(self, source_dict):
self.remove_tests(orig_file, 'sources', orig_source['name'])
self.merge_patch(orig_file, 'sources', orig_source)
self.add_to_pp_files(orig_file)

def build_env_vars_to_source_files(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this method where we should check to see if env vars start with SECRET_ENV_PREFIX, and (if so) not store their value / always invalidate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is using the stored env_var values, so probably that needs to happen earlier in the provider context env_var method.

Copy link
Contributor

Choose a reason for hiding this comment

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

We had a chance to discuss this offline, and arrived at: we should always store ***** as the value for secret env vars, i.e., neither store their values nor invalidate/re-parse files if the (unknown) value changes. This should work well with the intended use case for secret-prefixed env vars (packages.yml), or anticipated use in profiles.yml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was slightly simpler to just not store env vars starting with the secret prefix, because otherwise we have to convert when we read them in the partial parser too. Does this work for you?

@gshank gshank force-pushed the pp_sql_env_vars branch 2 times, most recently from 5e02006 to 54f2e55 Compare October 21, 2021 19:48
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.

LGTM. Only some minor suggestions.




class EnvVarTest(BasePPTest):
Copy link
Contributor

Choose a reason for hiding this comment

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

Great test! Very easy to follow.

core/dbt/parser/partial.py Show resolved Hide resolved
@gshank gshank merged commit 73af9a5 into main Oct 26, 2021
@gshank gshank deleted the pp_sql_env_vars branch October 26, 2021 15:16
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-redshift that referenced this pull request Oct 27, 2021
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* [#3885] Handle env_vars in partial parsing

* Comment method to build env_vars_to_source_files

automatic commit by git-black, original commits:
  73af9a5
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* [#3885] Handle env_vars in partial parsing

* Comment method to build env_vars_to_source_files

automatic commit by git-black, original commits:
  73af9a5
  dc65118
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* [#3885] Handle env_vars in partial parsing

* Comment method to build env_vars_to_source_files

automatic commit by git-black, original commits:
  307d47e
  73af9a5
  e2cd45b
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* [#3885] Handle env_vars in partial parsing

* Comment method to build env_vars_to_source_files

automatic commit by git-black, original commits:
  22db36c
  307d47e
  73af9a5
  e3fb923
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* [#3885] Handle env_vars in partial parsing

* Comment method to build env_vars_to_source_files

automatic commit by git-black, original commits:
  32c5598
  73af9a5
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
* [#3885] Handle env_vars in partial parsing

* Comment method to build env_vars_to_source_files

automatic commit by git-black, original commits:
  73af9a5
  a5ce658
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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Env vars + partial parsing
3 participants