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

Fix error with validation code (#956) #958

Merged
merged 3 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions dbt/context/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ def assert_var_not_none(self, var_name):
raw = self.local_vars[var_name]
if raw is None:
pretty_vars = self.pretty_dict(self.local_vars)
model_name = dbt.utils.get_model_name_or_none(self.model)
dbt.exceptions.raise_compiler_error(
self.NoneVarError.format(
var_name, model_name, pretty_vars
var_name, self.model_name, pretty_vars
),
self.model
)
Expand Down
53 changes: 53 additions & 0 deletions test/unit/test_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import mock
import unittest

from dbt.contracts.graph.parsed import ParsedNode
from dbt.context.common import Var
import dbt.exceptions

class TestVar(unittest.TestCase):
def setUp(self):
self.model = ParsedNode(
alias='model_one',
name='model_one',
schema='analytics',
resource_type='model',
unique_id='model.root.model_one',
fqn=['root', 'model_one'],
empty=False,
package_name='root',
original_file_path='model_one.sql',
root_path='/usr/src/app',
refs=[],
depends_on={
'nodes': [],
'macros': []
},
config={
'enabled': True,
'materialized': 'view',
'post-hook': [],
'pre-hook': [],
'vars': {},
'quoting': {},
'column_types': {},
},
tags=[],
path='model_one.sql',
raw_sql='',
description='',
columns={}
)
self.context = mock.MagicMock()

def test_var_not_none_is_none(self):
var = Var(self.model, self.context, overrides={'foo': None})
var.assert_var_defined('foo', None)
with self.assertRaises(dbt.exceptions.CompilationException):
var.assert_var_not_none('foo')

def test_var_defined_is_missing(self):
var = Var(self.model, self.context, overrides={})
var.assert_var_defined('foo', 'bar')
with self.assertRaises(dbt.exceptions.CompilationException):
Copy link
Member

Choose a reason for hiding this comment

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

this was raising AttributeError before, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. I reverted the fix commit and ran the test, and it fails with an AttributeError.

var.assert_var_defined('foo', None)