Skip to content

Commit

Permalink
sets schema for node before parsing raw sql (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin authored Sep 29, 2017
1 parent 9f365eb commit fd17c2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dbt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def parse_node(node, node_path, root_project_config, package_project_config,
config_dict.update(config.config)
node['config'] = config_dict

# Set this temporarily so get_rendered() below has access to a schema
profile = dbt.utils.get_profile_from_project(root_project_config)
default_schema = profile.get('schema', 'public')
node['schema'] = default_schema

context = dbt.context.parser.generate(node, root_project_config,
{"macros": macros})

Expand All @@ -232,7 +237,6 @@ def parse_node(node, node_path, root_project_config, package_project_config,
adapter.release_connection(profile, node.get('name'))

# Special macro defined in the global project
default_schema = context.get('schema')
schema_override = config.config.get('schema')
get_schema = context.get('generate_schema_name', lambda x: default_schema)
node['schema'] = get_schema(schema_override)
Expand Down
6 changes: 6 additions & 0 deletions dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def coalesce(*args):
return None


def get_profile_from_project(project):
target_name = project.get('target', {})
profile = project.get('outputs', {}).get(target_name, {})
return profile


def get_model_name_or_none(model):
if model is None:
name = '<None>'
Expand Down

0 comments on commit fd17c2e

Please sign in to comment.