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

put "this" var back into operation context #879

Merged
merged 2 commits into from
Jul 25, 2018
Merged
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
20 changes: 16 additions & 4 deletions dbt/context/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,22 @@ def generate(model, project_cfg, flat_graph, provider=None):
"try_or_compiler_error": try_or_compiler_error(model)
})

# Operations do not represent database relations, so 'this' does not apply
if model.get('resource_type') != NodeType.Operation:
context["this"] = get_this_relation(db_wrapper, project_cfg, profile,
model)
# Operations do not represent database relations, so there should be no
# 'this' variable in the context for operations. The Operation branch
# below should be removed in a future release. The fake relation below
# mirrors the historical implementation, without causing errors around
# the missing 'alias' attribute for operations
#
# https://github.com/fishtown-analytics/dbt/issues/878
if model.get('resource_type') == NodeType.Operation:
this = db_wrapper.adapter.Relation.create(
schema=target['schema'],
identifier=model['name']
)
else:
this = get_this_relation(db_wrapper, project_cfg, profile, model)

context["this"] = this

context = _add_tracking(context)
context = _add_validation(context)
Expand Down