dbt-labs / dbt-codegen

Macros that generate dbt code
https://hub.getdbt.com/dbt-labs/codegen/latest/
Apache License 2.0
464 stars 102 forks source link

Description doesn't inherit code blocks when using upstream_descriptions. #111

Closed diegodewilde closed 1 year ago

diegodewilde commented 1 year ago

Describe the bug

When using the generate_model_yaml functionality with upstream_descriptions it seems that the generated yaml file doesn't use the exact yaml description from upstream. Instead it uses the "compiled" description. This is a problem when using code blocks and goes directly against the reason to use code blocks.

Steps to reproduce

You can skip A by using the attached zip file which contains the necessary files. reproduce-files.zip

A. We need the following steps (1->3) to setup a demo environment.

  1. Create a model file dummy_model.sql with the following content:
    select
    'foo' as first_column
  2. Create a yaml file dummy_model.yml with the following content:
    
    version: 2

models:

The description about the first column model!

{% enddocs %}

4. Create a second model file `second_dummy_model.sql` with the following content:
```sql
select
    *
from {{ ref('dummy_model') }}

B. Now we can execute the following commands to generate the model yaml (using upstream descriptions).

dbt compile
dbt run-operation generate_model_yaml --args '{"model_names": ["second_dummy_model"], "upstream_descriptions": true}'

Expected results

The generated yaml file should contain the same column descriptions as the upstream model. In this case, this would need to be "{{ doc('dummy_model__first_column') }}". Full expected result would be:

version: 2

models:
  - name: second_dummy_model
    description: ""
    columns:
      - name: first_column
        description: "{{ doc('dummy_model__first_column') }}"

Actual results

However, the result is the "compiled" description as you can see below:

version: 2

models:
  - name: second_dummy_model
    description: ""
    columns:
      - name: first_column
        description: "The description about the `first column` model!"

Screenshots and log output

Not required.

System information

Not required.

Are you interested in contributing the fix?

Certainly, but I can't find a way to get the original description. Couldn't find it in the used graph object myself, so hopefully someone can lend a hand here! Asked it in the #advice-dbt-for-power-users channel on Slack as well with this post.

wtfzambo commented 1 year ago

Absolutely would love this feature.

However, I'm afraid that the inherited description comes from the graph object, and not from a parsing of the parent yml files, thus returning the actual description and not the macro.

I don't know if it would be possible to obtain what you're looking for. Not using pure dbt macros anyway.

github-actions[bot] commented 1 year ago

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

github-actions[bot] commented 1 year ago

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

ian-fahey commented 11 months ago

This call is coming from inside the house (dbt internal data team) and I also think this functionality would be incredible as I carry dozens of field descriptions from one rev rec model through the next five.

shelly-leaflink commented 1 month ago

Hi! Would love to inherit doc blocks instead of the description itself. Any chance of this being worked on in the near future?