From 38dc9fa23d1e025c430438773880e58e07a31536 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Wed, 25 Jul 2018 10:07:52 -0400 Subject: [PATCH 1/2] put "this" var back into operation context --- dbt/context/common.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dbt/context/common.py b/dbt/context/common.py index d2f23eda805..759061a43a0 100644 --- a/dbt/context/common.py +++ b/dbt/context/common.py @@ -407,10 +407,17 @@ 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. + # + # https://github.com/fishtown-analytics/dbt/issues/878 + if model.get('resource_type') == NodeType.Operation: + this = db_wrapper.adapter.Relation.create_from_node(profile, model) + else: + this = get_this_relation(db_wrapper, project_cfg, profile, model) + + context["this"] = this context = _add_tracking(context) context = _add_validation(context) From e6b21796c1629bfb5e805f87d8143d7952c6724a Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Wed, 25 Jul 2018 10:34:42 -0400 Subject: [PATCH 2/2] fix for catlalog generation --- dbt/context/common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dbt/context/common.py b/dbt/context/common.py index 759061a43a0..84a68616008 100644 --- a/dbt/context/common.py +++ b/dbt/context/common.py @@ -409,11 +409,16 @@ def generate(model, project_cfg, flat_graph, provider=None): # 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. + # 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_from_node(profile, model) + this = db_wrapper.adapter.Relation.create( + schema=target['schema'], + identifier=model['name'] + ) else: this = get_this_relation(db_wrapper, project_cfg, profile, model)