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

Default test name causes compilation error with --store-failures flag #925

Open
2 tasks done
ClauPet opened this issue Sep 30, 2024 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working case_sensitivity Issues related to dbt's case-sensitivity behavior store_failures Related to storing data test failures in the database triage

Comments

@ClauPet
Copy link

ClauPet commented Sep 30, 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

I have the following dbt model:

test.sql

column_name | val
-------------+-----
A           | 0.4
B           | 0.4

test.yml

models:
  - name: test
    columns:
      - name: column_name
        tests:
          - accepted_values:
              values: ['A', 'B', 'C'] 

After creating the model, I run the test doing dbt test --select test --store_failures. An empty table named accepted_values_test_column_name__a__b__c is created in the dbt_test__audit schema of my Redshift database. The second time I run the exact same command I get a compilation error saying that there is not table accepted_values_test_column_name__A__B__C.

Redshift by default uses case insensitive identifiers, e.g. table names. I know I could get around this by adding a custom lower case test names. However, this is not desirable with the amount of accepted values tests I have.

Expected Behavior

I would expect dbt to know of the case insensitivity of Redshift identifiers and not try to crate a table accepted_values_test_column_name__A__B__C.

Steps To Reproduce

  1. Create an accepted values test with capital test values
  2. run dbt test --store-failures twice

Relevant log output

Compilation Error in test accepted_values_test_column_name__A__B__C (models/master_data/test.yml)
  When searching for a relation, dbt found an approximate match. Instead of guessing
  which relation to use, dbt will move on. Please delete "reddw"."dbt_test__audit"."accepted_values_test_column_name__a__b__c", or rename it to be less ambiguous.
  Searched for: "reddw"."dbt_test__audit"."accepted_values_test_column_name__A__B__C"
  Found: "reddw"."dbt_test__audit"."accepted_values_test_column_name__a__b__c"

Environment

- Python:3.10.2
- dbt-core:1.7.11
- dbt-redshift: 1.7.5

Which database adapter are you using with dbt?

redshift

Additional Context

No response

@ClauPet ClauPet added bug Something isn't working triage labels Sep 30, 2024
@dbeatty10 dbeatty10 added case_sensitivity Issues related to dbt's case-sensitivity behavior store_failures Related to storing data test failures in the database labels Sep 30, 2024
@dbeatty10 dbeatty10 changed the title Default test name causes compilation error with --store-failures flag Default test name causes compilation error with --store-failures flag Oct 4, 2024
@dbeatty10
Copy link
Contributor

Thanks for reporting this @ClauPet !

I can't replicate this because we set enable_case_sensitive_identifier to true in our cluster’s parameter group via the Amazon Redshift console.

But I absolutely believe you are experiencing this because I've seen the unfortunate consequences of Redshift's default behavior of ignoring quoted identifiers first-hand before. See below for example code that I think would reproduce this when enable_case_sensitive_identifier=false (default).

The most direct way to overcome this to to set enable_case_sensitive_identifier to true, but I'm assuming that isn't an option for you.

In the meantime, I'm going to transfer this to the dbt-redshift repo because I don't think this affects any other dbt adapters.

Reprex

Create these files:

models/test.sql

select 'A' as column_name union all
select 'B' as column_name

models/test.yml

models:
  - name: test
    columns:
      - name: column_name
        tests:
          - accepted_values:
              values: ['A', 'B', 'C'] 

Run these commands:

dbt run --select test
dbt test --select test --store-failures
dbt test --select test --store-failures

@dbeatty10 dbeatty10 transferred this issue from dbt-labs/dbt-core Oct 4, 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 case_sensitivity Issues related to dbt's case-sensitivity behavior store_failures Related to storing data test failures in the database triage
Projects
None yet
Development

No branches or pull requests

2 participants