Skip to content

Commit

Permalink
skip tests that depend on nonexistent or disabled models (#617)
Browse files Browse the repository at this point in the history
* skip tests that depend on nonexistent or disabled models

* pep8, Fixes #616

* refactor
  • Loading branch information
drewbanin authored Jan 2, 2018
1 parent 94033d2 commit 011434d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
19 changes: 12 additions & 7 deletions dbt/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dbt.compat import basestring
from dbt.logger import GLOBAL_LOGGER as logger


class Exception(BaseException):
Expand Down Expand Up @@ -146,18 +147,22 @@ def ref_bad_context(model, target_model_name, target_model_package):
raise_compiler_error(error_msg, model)


def ref_target_not_found(model, target_model_name, target_model_package):
def get_target_not_found_msg(model, target_model_name, target_model_package):
target_package_string = ''

if target_model_package is not None:
target_package_string = "in package '{}' ".format(target_model_package)

raise_compiler_error(
"Model '{}' depends on model '{}' {}which was not found."
.format(model.get('unique_id'),
target_model_name,
target_package_string),
model)
return ("Model '{}' depends on model '{}' {}which was not found or is"
" disabled".format(model.get('unique_id'),
target_model_name,
target_package_string))


def ref_target_not_found(model, target_model_name, target_model_package):
msg = get_target_not_found_msg(model, target_model_name,
target_model_package)
raise_compiler_error(msg, model)


def ref_disabled_dependency(model, target_model):
Expand Down
18 changes: 7 additions & 11 deletions dbt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,13 @@ def process_refs(flat_graph, current_project):
node.get('package_name'))

if target_model is None:
dbt.exceptions.ref_target_not_found(
node,
target_model_name,
target_model_package)

if (dbt.utils.is_enabled(node) and not
dbt.utils.is_enabled(target_model)):
if dbt.utils.is_type(node, NodeType.Model):
dbt.exceptions.ref_disabled_dependency(node, target_model)
else:
node.get('config', {})['enabled'] = False
# This may raise. Even if it doesn't, we don't want to add
# this node to the graph b/c there is no destination node
node.get('config', {})['enabled'] = False
dbt.utils.invalid_ref_fail_unless_test(node,
target_model_name,
target_model_package)
continue

target_model_id = target_model.get('unique_id')

Expand Down
15 changes: 15 additions & 0 deletions dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,18 @@ def get_hashed_contents(model):

def flatten_nodes(dep_list):
return list(itertools.chain.from_iterable(dep_list))


def invalid_ref_fail_unless_test(node, target_model_name,
target_model_package):
if node.get('resource_type') == NodeType.Test:
warning = dbt.exceptions.get_target_not_found_msg(
node,
target_model_name,
target_model_package)
logger.debug("WARNING: {}".format(warning))
else:
dbt.exceptions.ref_target_not_found(
node,
target_model_name,
target_model_package)
8 changes: 8 additions & 0 deletions test/integration/001_simple_copy_test/models/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


# Confirm that this does not throw an exception for
# a missing ref to the disabled model
disabled:
constraints:
unique:
- id

0 comments on commit 011434d

Please sign in to comment.