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] Unit tests - expected varchar values are being truncated as integers #11322

Open
2 tasks done
cristi-envato opened this issue Feb 19, 2025 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working triage

Comments

@cristi-envato
Copy link

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 unit test setup with csv mock data:

unit_tests:
  - name: test_basic_search_id_logic
    description: Given a user performs a search within a session, expect all events within the search lifecycle to have the same basic_search_id
    model: <model_name>
    given:
      - input:  ref('<input_model_name>')
        format: csv
        rows: |
          id,session_id,event_name,custom_timestamp_utc
          1234abcd,"118172","118172",search,173
          2345efgh,"118172","118172",page_view,174
          3456ijkl,"118172","118172",view_item_list,175
          7890mnop,"118172","118172",select_item,176
          qrst1234,"118172","118172",page_view,177
          uvwx2345,"118172","118172",view_item,178
    expect:
      format: csv
      rows: |
        id,session_id,event_name,custom_timestamp_utc,basic_search_id
        qrst1234,"118172","118172",page_view,177,"118172173"
        3456ijkl,"118172","118172",view_item_list,175,"118172173"
        1234abcd,"118172","118172",search,173,"118172173"
        7890mnop"118172","118172",select_item,176,"118172173"
        uvwx2345,"118172","118172",view_item,178,"118172173"
        2345efgh,"118172","118172",page_view,174,"118172173"

And when I run dbt test --select test_type:unit against Redshift, it fails with the following message:
Image

I know it's a tricky one, as the docs state that dbt takes the value you provide and attempts to cast it to the data type as inferred from the input and output models (see docs). In this case basic_search_id is a concatenation of session_id (varchar) and custom_timestamp_utc (bigint) and In the model, I'm specifically casting custom_timestamp_utc to a varchar:

concat(session_id, custom_timestamp_utc::varchar) as basic_search_id

Expected Behavior

I expected that dbt would cast the expected values for basic_search_id to strings as I surrounded them in double quotes, therefore showing the whole value and not treat it as an integer and truncated it.

Steps To Reproduce

See above

Relevant log output

Environment

- dbt-core=1.9.0

Which database adapter are you using with dbt?

redshift

Additional Context

No response

@cristi-envato cristi-envato added bug Something isn't working triage labels Feb 19, 2025
@cristi-envato
Copy link
Author

I did find a workaround: if I specify the data_type in this model's _model.yml file, it gets inferred correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

1 participant