-
Notifications
You must be signed in to change notification settings - Fork 1.6k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Allow using macros in the documentation YAML #3277
Comments
@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. |
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. |
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:
|
@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 |
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. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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.
The text was updated successfully, but these errors were encountered: