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

Trim whitespace characters from schema names before creating #1074

Closed
mikekaminsky opened this issue Oct 17, 2018 · 2 comments
Closed

Trim whitespace characters from schema names before creating #1074

mikekaminsky opened this issue Oct 17, 2018 · 2 comments
Assignees
Labels
bug Something isn't working good_first_issue Straightforward + self-contained changes, good for new contributors!
Milestone

Comments

@mikekaminsky
Copy link
Contributor

mikekaminsky commented Oct 17, 2018

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                  |
@drewbanin
Copy link
Contributor

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.

@mikekaminsky
Copy link
Contributor Author

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!

@drewbanin drewbanin added bug Something isn't working good_first_issue Straightforward + self-contained changes, good for new contributors! labels Oct 22, 2018
@drewbanin drewbanin added this to the Wilt Chamberlain milestone Nov 28, 2018
@beckjake beckjake self-assigned this Dec 3, 2018
beckjake added a commit that referenced this issue Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good_first_issue Straightforward + self-contained changes, good for new contributors!
Projects
None yet
Development

No branches or pull requests

4 participants