Skip to content

Commit

Permalink
[dbt-labs#4523] Fix error with env_var in hook (dbt-labs#4524)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank authored Dec 20, 2021
1 parent b34a4ab commit 8463af3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Issue better error message for incompatible schemas ([#4470](https://github.com/dbt-labs/dbt-core/pull/4442), [#4497](https://github.com/dbt-labs/dbt-core/pull/4497))
- Remove secrets from error related to packages. ([#4507](https://github.com/dbt-labs/dbt-core/pull/4507))
- Prevent coercion of boolean values (`True`, `False`) to numeric values (`0`, `1`) in query results ([#4511](https://github.com/dbt-labs/dbt-core/issues/4511), [#4512](https://github.com/dbt-labs/dbt-core/pull/4512))
- Fix error with an env_var in a project hook ([#4523](https://github.com/dbt-labs/dbt-core/issues/4523), [#4524](https://github.com/dbt-labs/dbt-core/pull/4524))

### Docs
- Fix missing data on exposures in docs ([#4467](https://github.com/dbt-labs/dbt-core/issues/4467))
Expand Down
10 changes: 6 additions & 4 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,12 @@ def env_var(self, var: str, default: Optional[str] = None) -> str:
# If this is compiling, do not save because it's irrelevant to parsing.
if self.model and not hasattr(self.model, 'compiled'):
self.manifest.env_vars[var] = return_value
source_file = self.manifest.files[self.model.file_id]
# Schema files should never get here
if source_file.parse_file_type != 'schema':
source_file.env_vars.append(var)
# hooks come from dbt_project.yml which doesn't have a real file_id
if self.model.file_id in self.manifest.files:
source_file = self.manifest.files[self.model.file_id]
# Schema files should never get here
if source_file.parse_file_type != 'schema':
source_file.env_vars.append(var)
return return_value
else:
msg = f"Env var required but not provided: '{var}'"
Expand Down
3 changes: 3 additions & 0 deletions test/integration/014_hook_tests/test_run_hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from test.integration.base import DBTIntegrationTest, use_profile
import os


class TestPrePostRunHooks(DBTIntegrationTest):
Expand All @@ -22,6 +23,7 @@ def setUp(self):
'run_started_at',
'invocation_id'
]
os.environ['TERM_TEST'] = 'TESTING'

@property
def schema(self):
Expand All @@ -41,6 +43,7 @@ def project_config(self):
"{{ custom_run_hook('start', target, run_started_at, invocation_id) }}",
"create table {{ target.schema }}.start_hook_order_test ( id int )",
"drop table {{ target.schema }}.start_hook_order_test",
"{{ log(env_var('TERM_TEST'), info=True) }}",
],
"on-run-end": [
"{{ custom_run_hook('end', target, run_started_at, invocation_id) }}",
Expand Down

0 comments on commit 8463af3

Please sign in to comment.