dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.61k stars 1.59k forks source link

[CT-3067] [Bug] Docs blocks don't work in model versions #8540

Closed Gonzalo933 closed 11 months ago

Gonzalo933 commented 1 year ago

Is this a new bug in dbt-core?

Current Behavior

Currently, .yml with model definitions do not support using doc blocks inside the fields.

I believe this could be similar to #2913

Commenting or removing the doc block removes the error.

Expected Behavior

I would expect the doc to be loaded as a string.

Steps To Reproduce

with this model configuration:

version: 2

models:
  - name: working_model
        columns:
          - name: column_id
            description: '{{ doc("column_id_doc") }}'
  - name: error_model
    description: my description
    latest_version: 1
    versions:
      - v: 1
        config:
          alias: my_alias
        columns:
          - name: column_id
            description: '{{ doc("column_id_doc") }}'
      - v: 2
        columns:
          - name: other_id

DBT cloud Raises an error when trying to run the tests for the model.

Compilation Error
  Could not render {{ doc("column_id_doc") }}: 'doc' is undefined

Also, running dbt docs generate creates the right documentation for working_model and an empty string for the column column_id in the model error_model

Relevant log output

No response

Environment

dbt cloud

Which database adapter are you using with dbt?

snowflake

Additional Context

No response

jtcohen6 commented 1 year ago

Thanks @Gonzalo933! I was able to reproduce using the example you've provided, and I agree that the intended behavior is to support docs blocks for column-level descriptions at all levels.

Basically, while docs blocks are supported in the description field specified for columns at the top level, it isn't supported when specified for columns on a specific version:

models:
  - name: versioned_model
    description: '{{ doc("any_doc_block") }}'  # this works
    columns:
      - name: id
        description: '{{ doc("any_doc_block") }}'  # this works
    versions:
      - v: 1
        columns:
          - name: id
            description: '{{ doc("any_doc_block") }}'  # this does NOT work
jtcohen6 commented 1 year ago

Very similar to:

aranke commented 12 months ago

Next step: @aranke to check if fix for #8509 fixes this issue as well.

jtcohen6 commented 11 months ago

From estimation: