Repository: dbt-labs/dbt-core

Issue:
Trim whitespace characters from schema names before creating
### Issue description
Somehow when I was using DBT today, I created some schemas that had multiple whitespace characters in them (carriage returns `\n` and spaces). These were a huge pain to get rid of! DBT should prevent this by trimming whitespace from schema names.

### System information
The output of `dbt --version`:
```
installed version: 0.11.1
   latest version: 0.11.1
```

The operating system you're running on:
Mac OS

The python version you're using (probably the output of `python --version`)

```
Python 3.7.0
```

### Steps to reproduce
I'm ... not sure how I got into this state. It could have been from lots of cmd+C and interactive terminal work. I'm not sure I could reproduce it, but I don't think it would hurt to make DBT more defensive here!

Here's what some of my schemas looked like:
```
dwh=> \dn
              List of schemas
              name               |  owner
---------------------------------+----------
                                +| dbt
                                +|
                                +|
     msk                         |
                                +| dbt
     comparison                  |
```



Discussion:
hey @mikekaminsky - thanks for the report. It's possible this happened in your `generate_schema_name` macro. Eg. if you had:

```
{% macro generate_schema_name(custom_schema_name=none) -%}

  some_schema_name

{%- endmacro %}
```

Then you would see a schema name like `some_schema_name`.

Whereas if you had:

```
{% macro generate_schema_name(custom_schema_name=none) %}

  some_schema_name

{% endmacro %}
```

Your schema name would become:
```
"
   some_schema_name
"
```

The `-` character in `-%}` and `{%-` will tell jinja to trim trailing and leading whitespace. If you left those out, then the whitespace in the macro would be become significant.

I think it would be a good idea to add a `trim` call to the python code that calls this macro. Can't think of any reason why whitespace would be necessary or desirable in a schema name.


Whoah! I didn't realize those dashes were significant in jinja. Good to know! I still think it'd be worth putting in the python `trim` for the reasons you mention!

Resolving patch:
diff --git a/dbt/parser/base.py b/dbt/parser/base.py
--- a/dbt/parser/base.py
+++ b/dbt/parser/base.py
@@ -121,7 +121,7 @@ def parse_node(cls, node, node_path, root_project_config,
         schema_override = config.config.get('schema')
         get_schema = context.get('generate_schema_name',
                                  lambda x: default_schema)
-        parsed_node.schema = get_schema(schema_override)
+        parsed_node.schema = get_schema(schema_override).strip()
         parsed_node.alias = config.config.get('alias', default_alias)
 
         # Set tags on node provided in config blocks


Test patch:
diff --git a/test/integration/024_custom_schema_test/macros/schema.sql b/test/integration/024_custom_schema_test/macros/schema.sql
--- a/test/integration/024_custom_schema_test/macros/schema.sql
+++ b/test/integration/024_custom_schema_test/macros/schema.sql
@@ -1,6 +1,6 @@
 
-{% macro generate_schema_name(schema_name) -%}
+{% macro generate_schema_name(schema_name) %}
 
     {{ schema_name }}_{{ target.schema }}_macro
 
-{%- endmacro %}
+{% endmacro %}