Skip to content

[BUG] expect_column_values_to_have_consistent_casing handles NULL values incorrectly #27

@jvanbuel

Description

@jvanbuel

Is this a new bug in dbt-expectations?

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

Current Behavior

When testing a column for consistent casing, NULL values should not influence the result. In its current implementation, a expect_column_values_to_have_consistent_casing test fails when there are one or more NULL values in an otherwise cosistently-cased column and with display_inconsistent_columns set to false.
When setting display_inconsistent_columns to true, the test succeeds.

Expected Behavior

I expect NULL values to not affect the consistent casing test.

Steps To Reproduce

Run the test on a table with a single column with consistent casing:

-- models/test_casing_null.sql
{{ config(materialized='table') }}

select 
    'CONSISTENT' as text_column
union all
select 
    NULL as text_column

with a test

models:
  - name: test_casing_null
    description: "Test model for consistent casing with null values"
    columns:
      - name: text_column
        description: "Column with consistent casing but includes null"
        data_tests:
          - dbt_expectations.expect_column_values_to_have_consistent_casing

and observe that the test fails. When changing the last lines of the test to

...
        data_tests:
          - dbt_expectations.expect_column_values_to_have_consistent_casing:
                 display_inconsistent_columns: true

the test succeeds.

Relevant log output

With display_inconsistent_columns: false:

08:38:06  Running with dbt=1.10.6
08:38:06  Registered adapter: duckdb=1.9.4
08:38:07  Found 1 model, 1 test, 705 macros
08:38:07  
08:38:07  Concurrency: 4 threads (target='dev')
08:38:07  
08:38:07  1 of 1 START test dbt_expectations_expect_column_values_to_have_consistent_casing_test_casing_null_text_column  [RUN]
08:38:07  1 of 1 FAIL 1 dbt_expectations_expect_column_values_to_have_consistent_casing_test_casing_null_text_column  [FAIL 1 in 0.06s]
08:38:07  
08:38:07  Finished running 1 test in 0 hours 0 minutes and 0.23 seconds (0.23s).
08:38:07  
08:38:07  Completed with 1 error, 0 partial successes, and 0 warnings:
08:38:07  
08:38:07  Failure in test dbt_expectations_expect_column_values_to_have_consistent_casing_test_casing_null_text_column (models/schema.yml)
08:38:07    Got 1 result, configured to fail if != 0
08:38:07  
08:38:07    compiled code at target/compiled/inconsistent_casing_bug/models/schema.yml/dbt_expectations_expect_column_ed0b2e25c51a211be2e24567a6362177.sql
08:38:07  
08:38:07  Done. PASS=0 WARN=0 ERROR=1 SKIP=0 NO-OP=0 TOTAL=1

With display_inconsistent_columns: true:

08:38:41  Running with dbt=1.10.6
08:38:42  Registered adapter: duckdb=1.9.4
08:38:42  Found 1 model, 1 test, 705 macros
08:38:42  
08:38:42  Concurrency: 4 threads (target='dev')
08:38:42  
08:38:43  1 of 1 START test dbt_expectations_expect_column_values_to_have_consistent_casing_test_casing_null_text_column__True  [RUN]
08:38:43  1 of 1 PASS dbt_expectations_expect_column_values_to_have_consistent_casing_test_casing_null_text_column__True  [PASS in 0.03s]
08:38:43  
08:38:43  Finished running 1 test in 0 hours 0 minutes and 0.18 seconds (0.18s).
08:38:43  
08:38:43  Completed successfully
08:38:43  
08:38:43  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 NO-OP=0 TOTAL=1

Environment

- OS: macOS (M1)
- Python: 3.13.5
- dbt:1.10.6
- dbt-expectations: 0.10.9

Which database adapter are you using with dbt?

  • duckdb
  • postgres
  • trino

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions