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

[Bug] Error thrown when using unit tests mock data with whitespace in column names #10405

Closed
2 tasks done
thatguysimon opened this issue Jul 4, 2024 · 1 comment
Closed
2 tasks done
Labels
bug Something isn't working duplicate This issue or pull request already exists unit tests Issues related to built-in dbt unit testing functionality

Comments

@thatguysimon
Copy link

thatguysimon commented Jul 4, 2024

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When supplying unit tests with mock data of a source that has column names with whitespace:

given:
  - input: source('my_source', 'my_source_table')
    rows:
      - "Row ID": 28
      - "Some Other Column": Some value

The column name is not wrapped in quotes and the DB throws an error:

Database Error
    syntax error at or near "id"
    LINE 24:  as row id, 

Expected Behavior

The unit tests should be executed as with regular snake case column names.

Steps To Reproduce

  1. Define a source with whitespace in its column names:
    sources:
      - name: my_source
        tables:
          - name: my_source_table
            columns:
              - name: "Row ID"
              - name: "Some Other Column"
  2. Define a model called my_model that uses the source
  3. Define a unit test for the model:
    unit_tests:
      - name: test_thing
        model: my_model
        given:
          - input: source('my_source', 'my_source_table')
            rows:
              - "Row ID": 28
              - "Some Other Column": Some value
  4. Run the test

Relevant log output

...

-- Fixture for my_source
select 
    
    cast(28 as character varying)
 as row id, 
    
    cast('Some value' as character varying)
 as some other column

.
.
.

An error occurred during execution of unit test 'test_thing'. There may be an error in the unit test definition: check the data types.
  Database Error
    syntax error at or near "id"
    LINE 24:  as row id,

Environment

- OS: Debian 10
- Python: 3.10.9
- dbt: 1.8.3

Which database adapter are you using with dbt?

postgres

Additional Context

  1. Also tried to provide the values like so '"Row ID"': 28 but then the column name doesn't match the available columns:
    Invalid column name: '"row id"' in unit test fixture for 'my_source'.
      Accepted columns for 'my_source' are: ['row id', ...
    
  2. These column names with whitespace don't have any issues in other dbt features, just now with the introduction of unit tests.
@thatguysimon thatguysimon added bug Something isn't working triage labels Jul 4, 2024
@dbeatty10 dbeatty10 added the unit tests Issues related to built-in dbt unit testing functionality label Jul 8, 2024
@dbeatty10
Copy link
Contributor

Thanks for reaching out @thatguysimon !

The issue here looks to be the same as dbt-labs/dbt-adapters#205, so I'm going to close this as a duplicate.

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
@dbeatty10 dbeatty10 added duplicate This issue or pull request already exists and removed triage labels Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

No branches or pull requests

2 participants