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 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
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
Copy link
Member

Choose a reason for hiding this comment

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

did you mean to remove this? there are two things here, ref target not found (the thing doesn't exist) and ref disabled dependency (target is disabled). i think ref target not found should still be a thing -- did functional testing prove that not to be the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cmcarthur yeah -- this code doesn't do anything currently. Disabled nodes are not included in the graph as of #568.

I can leave it in, but I'm pretty sure it's dead code

Copy link
Member

Choose a reason for hiding this comment

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

gotcha

# 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 @@ -359,3 +359,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