-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Enable test project hooks, flags.WHICH #4004
Conversation
@gshank I'd appreciate your thoughts here, given your recent work on the |
de77e24
to
ead4ba1
Compare
I agree that exporting the entire flags module feels wrong. We probably want to make a cleaner break between things that we support people looking up in jinja and things that are just for internal use. Also might want to prevent people from setting some of them directly. There is a dictionary available from get_flag_dict, but it doesn't have the subcommand flags in it. The args object has gotten to act like a global setting store, but I'm not certain how I feel about that. We've expanded its use as a cli arg store quite past the original purpose, but it's just a Namespace class at the moment, and there's no behavior associated with it. It might be better to create an internal Settings object and copy the relevant args into it. We could have a read-only dictionary version of allowed settings available to jinja? The flags/args/settings discussion aside, enabling this for tests seems like a good 1.0 feature. |
@gshank I strongly agree with this. I'd be very comfortable with explicitly enumerating exactly which args/flags/settings should be accessible to the Jinja context. How tricky do you think this might be to implement? Separately, would there be a way that we could offer backwards compatibility for folks who are used to reading a specific flag value into the Jinja context as |
I think there would be a bunch of trivial changes, so a fair number of lines of code to change, but not hard and mostly greppable. I'm thinking we'd replace internal use of flags entirely with a Settings object (probably a global one, kind of like the current adapter) and leave the flags module for compatibility for users. We kind of overuse the current args in a number of places so it's possible that would be a bit tricky to tease apart. The RPC server is going to be changing soon, so we might want to consult that team about what would work for them too. |
I left it as a TODO to rework the |
ead4ba1
to
caf0318
Compare
caf0318
to
a3a72ce
Compare
a3a72ce
to
ff6a443
Compare
* Turn on project hooks test task * Add flags.WHICH * Rm unused env vars (RPC) * Add changelog entry automatic commit by git-black, original commits: 4bda8c8
…mentation (#3246) ## What are you changing in this pull request and why? The `on-run-start` and `on-run-end` hooks are documented in the [build/hooks-operations](https://docs.getdbt.com/docs/build/hooks-operations) page, but it doesn't reflect that they run after `dbt test` (following [dbt-core#4004](dbt-labs/dbt-core#4004)): https://github.com/dbt-labs/docs.getdbt.com/blob/efe200c0ba5c4f87641d82b1d7bc9a3a83b20696/website/docs/docs/build/hooks-operations.md?plain=1#L35-L36 This PR will add `dbt test` to the list in both of these bullets ## Checklist - [x] Review the [Content style guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md) and [About versioning](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#adding-a-new-version) so my content adheres to these guidelines. - [ ] Add a checklist item for anything that needs to happen before this PR is merged, such as "needs technical review" or "change base branch."
resolves #3463
Previously
dbt test
(and onlydbt test
) would not runon-run-start
andon-run-end
hooks.This made sense in a time when test didn't actually create objects in the database, and the main motivation of
on-run-end
hooks was to rungrant
statementsm or other object/schema-level resource maintenance.This carved-out exception has proven painful, though, because the
{{ results }}
context object, available only in theon-run-end
context, contains a lot of valuable metadata (e.g. set of all test statuses/failures) that folks want to log, drop in the database, etc. (See: slack thread)Change
run
,test
,seed
,snapshot
, i.e. the tasks included bybuild
. (Still excluded:compile
,docs generate
,list
,source freshness
, etc.)WHICH
, that gives users a way to run a specific hook (or not) depending on the current askCommentary & questions
dbt build
as the task to do it all.dbt.core.flags
module to the Jinja context! Would we be better off exposing just a key-value dict containing all user-exposed flags/args?flags.SELECT
,flags.EXCLUDE
,flags.SELECTOR
. Or should we instead construct a genericargs
object that has it all?flags
values are expected to change at execution time, in any invocation, so users must not use these as inputs to parse-time values (ref/source + configs) with partial parsing enabled—otherwise bad things will happen. It's also just not a good pattern! In my dream of dreams, a world where we've truly separate parsing from execution, these flags should returnNone
at parse time. Is that a worthy thing to aspire for?Checklist
CHANGELOG.md
and added information about my change to the "dbt next" section.