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

add exceptions.warn to the dbt context (#1970) #1977

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,19 @@ def warn_or_raise(exc, log_fmt=None):
logger.warning(msg)


def emit_warning(msg, node=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just call this warn?

# there's no reason to expose log_fmt to macros - it's only useful for
# handling colors
return warn_or_error(msg, node=node)


# Update this when a new function should be added to the
# dbt context's `exceptions` key!
CONTEXT_EXPORTS = {
fn.__name__: fn
for fn in
[
emit_warning,
missing_config,
missing_materialization,
missing_relation,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% do exceptions.emit_warning('warning: everything is terrible but not that terrible') %}
Copy link
Contributor

Choose a reason for hiding this comment

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

😂

select 1 as id
20 changes: 20 additions & 0 deletions test/integration/013_context_var_tests/test_context_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import os

import pytest

import dbt.exceptions


class TestContextVars(DBTIntegrationTest):

Expand Down Expand Up @@ -133,3 +137,19 @@ def test_postgres_env_vars_prod(self):
self.assertEqual(ctx['target.user'], 'root')
self.assertEqual(ctx['target.pass'], '')
self.assertEqual(ctx['env_var'], '1')


class TestEmitWarning(DBTIntegrationTest):
@property
def schema(self):
return "context_vars_013"

@property
def models(self):
return "emit-warning-models"

@use_profile('postgres')
def test_postgres_emit_warning(self):
with pytest.raises(dbt.exceptions.CompilationException):
self.run_dbt(['run'], strict=True)
self.run_dbt(['run'], strict=False, expect_pass=True)