-
Notifications
You must be signed in to change notification settings - Fork 977
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
Add behavior change flag docs for adapter maintainers #6092
Add behavior change flag docs for adapter maintainers #6092
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
||
Starting in `dbt-adapters==1.5.0` and `dbt-core==1.8.7`, adapter maintainers have the ability to implement their own behavior change flags. | ||
For more information on what a behavior change is, please refer to [Behavior changes](https://docs.getdbt.com/reference/global-configs/behavior-changes). | ||
To implement a behavior change flag, provide a name, a default setting (`True` / `False`), and optional source, and either a description or a link to the flag's documentation on docs.getdbt.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To implement a behavior change flag, provide a name, a default setting (`True` / `False`), and optional source, and either a description or a link to the flag's documentation on docs.getdbt.com. | |
To implement a behavior change flag, you will need to provide a name for the flag, a default setting (`True` / `False`), optional source, and a description and/or a link to the flag's documentation on docs.getdbt.com. We recommend having a description and documentation link whenever possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also what is source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source
is basically a namespace. I would list the adapter as the source for adapter behavior flags. But the framework can be used elsewhere, so I don't force that. I also provide a default that takes the calling module, so that even if the maintainer does not add a source, there's still something that we can use to differentiate flags with the same name across multiple adapters (or not in an adapter at all). I wanted to try and automate it since it would feel silly to need to specify the adapter for every flag. We could probably be smarter than this and set it in BaseAdapter
somehow when they get registered.
|
||
</File> | ||
|
||
It's best practice to evaluate a behavior flag as few times as possible. This will make it easier to remove once the behavior change has matured. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best practice to evaluate a behavior flag as few times as possible.
what does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't pepper the code with a bunch individual checks like it's a configuration. It should truly represent "a legacy way" and "a novel way".
The dbt-redshift
example is a good one. Depending on whether we use the SDK or not, we either call the macro, or we call the SDK. We check the flag once.
In more complicated scenarios this may not be possible. Take Iceberg support for example. We need to check the flag in list relations
and we also need to check it when creating a table in the create table
macro. So we need to check it twice, there's really no way around that. But let's look at the create table
macro in particular. We should just have two versions of that macro, the legacy version without Iceberg and the novel way with Iceberg; these are gated by the flag. That's good.
Using two completely different versions of the code will result in a lot of duplicated code though. Both versions need a name, they need to put the sql at the end, they have shared options like warehouse
, etc. But there are multiple points where they differ as well. There are different config options like external_volume
. One uses create table my_table as...
and the other uses create iceberg table my_table as...
. So there will be an intuitive push towards DRY code where you can embed a check inside the macro at each point where it differs. That's not good. The behavior flag is becoming part of the code, and can more easily contribute to bugs in the code, in particular in the legacy code which was supposed to be gated from this whole change in the first place.
Co-authored-by: Amy Chen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mikealfare ! |
What are you changing in this pull request and why?
We added behavior flags for adapter maintainers to use on first- and third-party adapters. This PR adds documentation explaining how to configure and use behavior flags.
Checklist