diff --git a/dbt/context/common.py b/dbt/context/common.py index 9524eb4ed5e..1a0892f68e1 100644 --- a/dbt/context/common.py +++ b/dbt/context/common.py @@ -285,7 +285,7 @@ def generate(model, project, flat_graph, provider=None): "sql_now": adapter.date_function(), "fromjson": fromjson(model), "target": target, - "this": dbt.utils.Relation(adapter, model, use_temp=True) + "this": dbt.utils.Relation(profile, adapter, model, use_temp=True) }) context = _add_tracking(context) diff --git a/dbt/context/parser.py b/dbt/context/parser.py index 49724f5da40..bf254bb3636 100644 --- a/dbt/context/parser.py +++ b/dbt/context/parser.py @@ -19,7 +19,7 @@ def ref(*args): dbt.exceptions.ref_invalid_args(model, args) adapter = get_adapter(profile) - return dbt.utils.Relation(adapter, model) + return dbt.utils.Relation(profile, adapter, model) return ref diff --git a/dbt/context/runtime.py b/dbt/context/runtime.py index bac4f5c40b3..1a67ab1f5b1 100644 --- a/dbt/context/runtime.py +++ b/dbt/context/runtime.py @@ -52,7 +52,7 @@ def do_ref(*args): model['extra_ctes'][target_model_id] = None adapter = get_adapter(profile) - return dbt.utils.Relation(adapter, target_model) + return dbt.utils.Relation(profile, adapter, target_model) return do_ref diff --git a/dbt/utils.py b/dbt/utils.py index 1b5913e7065..16fb1e585a8 100644 --- a/dbt/utils.py +++ b/dbt/utils.py @@ -33,9 +33,7 @@ class ExitCodes(object): class Relation(object): - def __init__(self, adapter, node, use_temp=False): - self._adapter = adapter - + def __init__(self, profile, adapter, node, use_temp=False): self.node = node self.schema = node.get('schema') self.name = node.get('name') @@ -48,6 +46,21 @@ def __init__(self, adapter, node, use_temp=False): self.materialized = get_materialization(node) self.sql = node.get('injected_sql') + self.do_quote = self._get_quote_function(profile, adapter) + + def _get_quote_function(self, profile, adapter): + + # make a closure so we don't need to store the profile + # on the `Relation` object. That shouldn't be accessible in user-land + def quote(schema, table): + return adapter.quote_schema_and_table( + profile=profile, + schema=schema, + table=table + ) + + return quote + def _get_table_name(self, node): return model_immediate_name(node, dbt.flags.NON_DESTRUCTIVE) @@ -56,17 +69,13 @@ def final_name(self): msg = "final_name() was called on an ephemeral model" dbt.exceptions.raise_compiler_error(msg, self.node) else: - return self._adapter.quote_schema_and_table(profile=None, - schema=self.schema, - table=self.name) + return self.do_quote(self.schema, self.name) def __repr__(self): if self.materialized == 'ephemeral': return '__dbt__CTE__{}'.format(self.name) else: - return self._adapter.quote_schema_and_table(profile=None, - schema=self.schema, - table=self.table) + return self.do_quote(self.schema, self.table) def coalesce(*args):