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

skip tests that depend on nonexistent or disabled models #617

Merged
merged 3 commits into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 11 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,21 @@ 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 ref_target_not_found(model, target_model_name, target_model_package,
warn=False):
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)
msg = ("Model '{}' depends on model '{}' {}which was not found or is"
" disabled".format(model.get('unique_id'),
target_model_name,
target_package_string))
if warn:
logger.debug("WARNING: {}".format(msg))
else:
raise_compiler_error(msg, model)


def ref_disabled_dependency(model, target_model):
Expand Down
7 changes: 6 additions & 1 deletion dbt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ def process_refs(flat_graph, current_project):
current_project,
node.get('package_name'))

node_is_test = (node.get('resource_type') == NodeType.Test)
if target_model is None:
dbt.exceptions.ref_target_not_found(
node,
target_model_name,
target_model_package)
target_model_package,
warn=node_is_test)

if node_is_test:
continue
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't seem right to me... these dbt.exceptions calls should raise. i'd pull the message out of ref_target_not_found and then make this more explicit:

if target_model is None:
    if node.get('resource_type') == NodeType.Test:
        logger.info(warning)
        continue
    else:
        dbt.exceptions.ref_target_not_found( ... )


if (dbt.utils.is_enabled(node) and not
dbt.utils.is_enabled(target_model)):
Expand Down
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