Replies: 11 comments 8 replies
-
@pcasteran I really appreciate you opening this issue. I am going to ask you to be more specific :)
What other advanced use cases do you have in mind? If we're both thinking that the primary use case would be extending/inheriting descriptions, as is described by #2995, then I'll share how I'm thinking about that problem, and why this isn't my preferred solution (at least for now). Problem: There's a lot of duplicated code in projects today, defining resource properties on one object that apply equally to another object. Desired future state: Users can extend resource properties from one model/column/etc to another, without:
With that in mind, let's think about this specific proposal: expanding the context available when dbt renders Pros:
Cons:
So: I want to hear what other use cases you're thinking about. I agree completely with the desire for inheritable/extensible descriptions—I just don't think this is the right way there. |
Beta Was this translation helpful? Give feedback.
-
This adds a level of complexity, but it would be ideal if this ignored macros or functions inside a code tag within the markdown as well. For example, dbt tries to run this ref() right now when it's inside a code tag:
but it would be preferable if that code block was left as-is. Maybe this is just a nice-to-have after a first pass enabling more functionality. I didn't open this issue but I'm interested in it as well. I really like the suggestions going on in #2995, and #1334 describes my original use case even though I didn't open that one either! Overall, having access to more functions/macros would be handy. I'd love to contribute but I'm not at a point where I'd be very useful just yet on back-end stuff. And maybe the code-tag thing is a separate issue, I can split it out if that's helpful. |
Beta Was this translation helpful? Give feedback.
-
Thanks for taking the time to look at my proposal and for your detailed answer @jtcohen6. First, I want to clarify the scope of this discussion. What I'm actually proposing is to enable more macros to be used during the doc rendering, it is not a proposal for documentation inheritance. I may plan to use it for this use-case in the short term but the proposal was more general than that. Besides column doc inheritance, I would also like to access some attributes of other models in my documentation like -- Now regarding the more specific topic of documentation reuse, there are many possible ways to achieve it and maybe there should not be only one implemented. Performance wise, I'm not sure there would be a penalty using this kind of macro as, if I remember correctly the code I saw, dbt caches the columns description and only performs Jinja rendering once per column. -- Regarding the use of YAML anchors, is there a discusion about it other than #1790 ? I'm not really convinced this is the way to go as it raises some concerns:
|
Beta Was this translation helpful? Give feedback.
-
@pcasteran Apologies for the delay in getting back to you! This is something I continue to think about, and I'd like to find the right way to do it, possibly next year. For now, this has to wait until after dbt-core v1.0, which is our top development priority for dbt-core for the rest of the year. A similar idea just came in from @brittianwarner over in #3827, with the specific thought of more dynamic support in |
Beta Was this translation helpful? Give feedback.
-
Just came across a similar problem when trying to add dynamic content to the docs. I'd just assumed I could use macros in my docs. Found out otherwise then found this issue. My use case is that I'm trying to insert some data quality metrics into my docs by running a query and using the results in the docs. I'd like to be able to keep my query as a macro (organized with my macros for models) and then have it be called when I'm running docs generate to fill in the results. |
Beta Was this translation helpful? Give feedback.
-
Hey all, I was looking into using macros to simplify some of my documentation blocks. Want I want is to be able to define a macro like:
And be able to use it in the table:
- description: |
{{doc(...)}}
Code example:
{{client_example("current_table")}} From an end-user perspective, it doesn't seem to be a complicated feature to add, but I'm sure there is something behind the scenes that is stopping this from progressing. I've found several discussions around the topic (#3827, #2995, and this one) but none has had a clear outcome. Is there a place summarizing the status of this feature? |
Beta Was this translation helpful? Give feedback.
-
In my case, I would like to see this to avoid repeating logic in macros and the YAML file with our sources. In our data warehouse, we have different source schemas for production and development, right now we are doing something like this: version: 2
sources:
- name: "{{ target.schema }}"
schema: |
{%- if env_var("DBT_ENVIRONMENT", "dev") == "dev" -%}
dev_schema
{%- else -%}
prod_schema
... The problem is we also have to do the same logic in some hooks, and I would really like to just have one macro that applies this logic wherever is needed (keeping it DRY). Ideally, it would be as simple as: version: 2
sources:
- name: "{{ target.schema }}"
schema: "{{ get_source_schema_from_env() }}"
... |
Beta Was this translation helpful? Give feedback.
-
@jtcohen6 out of curiosity can this issue be consolidated with others? I see it's getting stale but I suspect the intent of this proposal deserves an LOE assessment i feel like the approach doesn't have to be arbitrary macros, since much of the value in the env switching use case could be solved by baking a concept of environments/targets more deeply into the But it would be nice to be able to call macros (or callable python functions to avoid parsing) in the yml file, so long as there are clear rules on what those macros can do, and ideally, dedicate a new top level directory called something like |
Beta Was this translation helpful? Give feedback.
-
@drewbanin @jtcohen6 is it at all possible to get eyes on this? the solutions proposed here are functional but not at all preferable. I'd really like to have some sort of special directory in which I can define macros which can be used in yaml files. eg generate_custom_database_name seems like it should be usable here for unified dispatch logic, OR perhaps it could be baked into the source function? either way, compositional dynamism would be super nice. |
Beta Was this translation helpful? Give feedback.
-
Hi, just want to echo the above. I have a similar use-case as the above example where I want to be able to set the database/schema based on target values. I think for now I will pass a variable to get the functionality I need, but would much prefer to be able to do this via a macro. |
Beta Was this translation helpful? Give feedback.
-
Hi all, want to leave link to opendbt project here. Where you can easily add this kind of features to dbt-core in an elegant way. Feel free to check it out and add the features you like to see in dbt-core |
Beta Was this translation helpful? Give feedback.
-
Describe the feature
Currently, only the
doc
macro is available in the Jinja rendering context used for the doc generation.It would be useful to add all the macros available in the project, as it is the case during the compilation of the models.
The use-case I'm trying to implement is to inherit the columns' description between all the model layers without having to copy-paste them (see this comment).
Describe alternatives you've considered
See the discussion on 2995.
Additional context
I have looked at the code and the reason why we can't use macros in the documentation comes from the fact that the
DocsRuntimeContext
class inherits fromSchemaYamlContext
whereas the context used during model compiltation inherits fromManifestContext
which is responsible for adding the macros in the context used during Jinja rendering.As these classes are not documented it's quite difficult to figure out their responsibilities and the reasons behind this type hierarchy. But maybe modifying the
SchemaYamlContext
to inherit fromManifestContext
would do the trick and enable the use of macros during the processing of the documentation.Who will this benefit?
Anyone who wants to write "advanced" documentation using some cool features of dbt would benefit from this feature.
Inheriting column's description and test from previous models is one example. There would also be other usages for advanced formatting of the documentation.
Are you interested in contributing this feature?
I would be interested in contributing but I would need some pointers on how to achieve this.
Beta Was this translation helpful? Give feedback.
All reactions