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

[CT-2811] [Bug] When adding data_type to a model yml, there is an error KeyError: 'data_type' #8063

Closed
2 tasks done
jan-benisek opened this issue Jul 10, 2023 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working model_contracts

Comments

@jan-benisek
Copy link

jan-benisek commented Jul 10, 2023

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 am trying to use contracts in dbt and therefore adding data_type, however I am getting KeyError: 'data_type'

Expected Behavior

The above should work, just like described in your documentation.

Steps To Reproduce

I have a simple model my_model.sql:

{{
    config(
        schema='tools',
        materialized='table',
        dist='all'
    )
}}


select
    lt.tool_raw,
    lt.tool

from {{ ref('foo') }} as lt -- this is a seed

This model has a description in yml file:

version: 2

models:
  - name: foo
    description: xyz
    columns:
      - name: abc
      
  - name: my_model
    description: foobar
    config:
      contract:
        enforced: true
    columns:
      - name: tool_raw
        data_type: varchar(20)
        constraints:
          - type: primary_key
            warn_unenforced: False 
        description: raw name of tool
      - name: tool
        description: tool name

When I run dbt run -s my_model I get an error (see below)

Relevant log output

15:08:15  Running with dbt=1.5.1
15:08:16  Found 247 models, 471 tests, 0 snapshots, 0 analyses, 1020 macros, 2 operations, 11 seed files, 60 sources, 86 exposures, 8 metrics, 0 groups
15:08:16  
15:08:19  Concurrency: 12 threads (target='dev')
15:08:19  
15:08:19  1 of 1 START sql table model dev_j.my_model ................................. [RUN]
15:08:19  Unhandled error while executing 
'data_type'
15:08:19  1 of 1 ERROR creating sql table model dev_j.my_model ........................ [ERROR in 0.08s]
15:08:20  
15:08:20  Running 2 on-run-end hooks
15:08:20  1 of 2 START hook: smallpdf.on-run-end.0 ....................................... [RUN]
15:08:20  1 of 2 OK hook: smallpdf.on-run-end.0 .......................................... [OK in 0.00s]
15:08:20  2 of 2 START hook: smallpdf.on-run-end.1 ....................................... [RUN]
15:08:20  2 of 2 OK hook: smallpdf.on-run-end.1 .......................................... [OK in 0.00s]
15:08:20  
15:08:20  
15:08:20  Finished running 1 table model, 2 hooks in 0 hours 0 minutes and 3.24 seconds (3.24s).
15:08:20  
15:08:20  Completed with 1 error and 0 warnings:
15:08:20  
15:08:20  'data_type'
15:08:20  
15:08:20  Done. PASS=0 WARN=0 ERROR=1 SKIP=0 TOTAL=1

In the dbt.log, I can see this:

File "/Users/j/.pyenv/versions/3.9.9/lib/python3.9/site-packages/dbt/adapters/base/impl.py", line 1342, in render_raw_columns_constraints
    rendered_column_constraint = [f"{v['name']} {v['data_type']}"]
KeyError: 'data_type'

Environment

  • OS: Mac
  • Python: Python 3.9.9
  • dbt: core: 1.5.1, dbt-redshift: 1.5.7

Which database adapter are you using with dbt?

redshift

Additional Context

No response

@jan-benisek jan-benisek added bug Something isn't working triage labels Jul 10, 2023
@github-actions github-actions bot changed the title [Bug] When adding data_type to a model yml, there is an error KeyError: 'data_type' [CT-2811] [Bug] When adding data_type to a model yml, there is an error KeyError: 'data_type' Jul 10, 2023
@dbeatty10 dbeatty10 self-assigned this Jul 10, 2023
@dbeatty10
Copy link
Contributor

dbeatty10 commented Jul 10, 2023

Thanks for opening this @jan-benisek !

All columns will need to have data_type defined. Could you try giving the tool column a data type like this?

      - name: tool
        description: tool name
        data_type: varchar(20)

That should solve the particular issue you are running into.

As a follow-up, dbt should raise a better error message when a data_type is missing for a column that is part of an enforced contract.

@dbeatty10 dbeatty10 removed their assignment Jul 10, 2023
@jan-benisek
Copy link
Author

Hi @dbeatty10 , should have thought of that, adding data_type to each column definitely works! I was probably confused with that error.
Thanks for the quick response.

@dbeatty10
Copy link
Contributor

You are welcome @jan-benisek!

We opened #8070 to raise a better error message in the future.

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

No branches or pull requests

3 participants