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

sets schema for node before parsing raw sql #541

Merged
merged 1 commit into from
Sep 29, 2017
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
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
Copy link
Member

Choose a reason for hiding this comment

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

couldn't this render in the wrong schema for multi-schema setups?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it might, but that would only happen during parsing, so it shouldn't have any effect. If other functions come along in the future, they'll get a somewhat sane value for a schema instead of None.


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