Skip to content
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

Fix some issues around global-scoped vars #2477

Merged
merged 2 commits into from
May 21, 2020
Merged

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented May 20, 2020

resolves #2469
resolves #2473
resolves #2472

Description

  • Fix global-level var rewriting from v2 -> v1

    • to do this, I inverted how var rewriting works: This skips including vars for packages that aren't actually used in the project, which I am not sorry about. It does mean that top-level vars can't be dicts, which we should absolutely document, but I also feel pretty good about. I think could add them in with the + syntax in the future.
  • Add top-level vars to more lookup fields

    • A few places handle vars, and a couple only handled the package-scoped ones. I believe I've resolved all of them.
  • When a user calls var() in a generate_*_name macro, on failure it now raises (like at runtime)

    • to do that, I added a new special provider that those macros use that mostly acts like the parse-time context (because it is), except var and config act as if it were runtime. Maybe config.get just should not work at all?
  • When a node has no FQN, pretend the FQN is just the package name when returning vars

    • This makes most things behave reasonably. I think in an ideal world the generate_*_name macros would somehow resolve vars against the node they're passed instead of the context's node. That's a much more complicated problem that probably deserves its own issue/PR process!

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label May 20, 2020
Fix global-level var rewriting from v2 -> v1
Add top-level vars to more lookup fields
When a user calls var() in a `generate_*_name` macro, on failure it now raises (like at runtime)
When a node has no FQN, pretend the FQN is just the package name when returning vars
Add tests
Change variables named `l` to `log`
Make IsFQNResource runtime type-checkable and use that to handle the FQN check
Make the GenerateNameProvider its own top-level Provider type
@beckjake beckjake requested review from drewbanin and kwigley May 20, 2020 19:06
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, but otherwise this LGTM


project_type_vars.update({
k: v for k, v in src_vars.items()
if not isinstance(v, dict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the thinking here? Is it that we don't want to provide package-scoped vars to the wrong package? It also means that you can't provide a global var that is a dict to a v1 package, right?

I'm curious what the ramifications would be if we removed this filter and added all of the src_vars to the v1 package's vars

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. We can remove that if not isinstance, I thought it made the debug dictionary really a pain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, that's fine - let's ship it as-is and I'll be sure to update the docs accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants