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 #6497: Support global flags passed in after subcommands #8670

Merged
merged 5 commits into from
Sep 26, 2023
Merged

Conversation

aranke
Copy link
Member

@aranke aranke commented Sep 19, 2023

resolves #6497

Problem

Solution

Checklist

  • I have read the contributing guide and understand what's expected of me
  • 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
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@aranke aranke requested a review from a team as a code owner September 19, 2023 13:05
@cla-bot cla-bot bot added the cla:yes label Sep 19, 2023
@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (aa86fdf) 86.61% compared to head (168f846) 82.74%.

❗ Current head 168f846 differs from pull request most recent head 913b1cd. Consider uploading reports for the commit 913b1cd to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8670      +/-   ##
==========================================
- Coverage   86.61%   82.74%   -3.87%     
==========================================
  Files         176      176              
  Lines       25678    25692      +14     
==========================================
- Hits        22240    21260     -980     
- Misses       3438     4432     +994     
Flag Coverage Δ
integration 77.81% <100.00%> (-5.56%) ⬇️
unit 65.17% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
core/dbt/cli/main.py 96.64% <100.00%> (-2.06%) ⬇️

... and 62 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

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

Mea culpa - I had missed adding the 1.5 + 1.6 backport labels to #6497. Ideally we could offer the same consistency for all our CLIs starting with v1.5+. Given how "clean" this change looks, how would you feel about backporting the change (at least the approach if not the exact commit diff) to 1.5.latest + 1.6.latest?

@@ -118,6 +119,44 @@ def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult:
)


# approach from https://github.com/pallets/click/issues/108#issuecomment-280489786
def global_flags(func):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is neat!

@jtcohen6 jtcohen6 added the user docs [docs.getdbt.com] Needs better documentation label Sep 20, 2023
@aranke
Copy link
Member Author

aranke commented Sep 20, 2023

@jtcohen6 These flags need to be set at the global level, and there doesn't seem to be an easy way to globalize them everywhere:

@p.warn_error
@p.warn_error_options
@p.log_format

Do you want me to continue working on this, or should I merge this PR as-is and create a backlog ticket to handle these edge cases?

@aranke
Copy link
Member Author

aranke commented Sep 20, 2023

Given how "clean" this change looks, how would you feel about backporting the change (at least the approach if not the exact commit diff) to 1.5.latest + 1.6.latest?

I'm fine with back porting the PR in its current state to 1.5 and 1.6, but if the acceptance criteria include back porting the three errant flags highlighted above, I might need to rethink.

@jtcohen6
Copy link
Contributor

@aranke That's odd - it's only those three flags which are being difficult? Do you have any sense of why?

@aranke
Copy link
Member Author

aranke commented Sep 20, 2023

Do you have any sense of why?

I'm not certain, honestly, but could be that they are being passed down incorrectly.
I can keep digging for a little, but don't want to delay this PR if there isn't an easy fix.

@aranke
Copy link
Member Author

aranke commented Sep 26, 2023

I've tried many combinations, and it looks like the order in which the parameter decorators are passed in matters.

Creating a backlog ticket (#8715) to investigate further, but I don't think we need to hold up this PR to globalize the three remaining flags.

@jtcohen6
Copy link
Contributor

@aranke Thanks for investigating & opening the ticket! We should try to get that tech debt ticket resolved — it's important for our ability to present consistent documentation & CLI behavior (dbt-labs/docs.getdbt.com#4041) — but I agree that it shouldn't block merging the brunt of the work in this PR.

Copy link
Member

@emmyoop emmyoop left a comment

Choose a reason for hiding this comment

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

LGTM

@aranke aranke merged commit f17c1f3 into main Sep 26, 2023
97 checks passed
@aranke aranke deleted the fix_6497 branch September 26, 2023 15:16
@FishtownBuildBot
Copy link
Collaborator

Opened a new issue in dbt-labs/docs.getdbt.com: dbt-labs/docs.getdbt.com#4129

Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -167,10 +178,10 @@ def cli(ctx, **kwargs):
# dbt build
@cli.command("build")
@click.pass_context
@global_flags
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice change! What happens when a flag in global flags got passed in twice at different level with different value, which one wins?

Copy link
Member Author

Choose a reason for hiding this comment

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

We throw an error, similar to existing behavior.

Product guidance from jerco: #6497 (comment)

Test:

def test_duplicate_flags_raises_error(self):
parent_context = self.make_dbt_context("parent", ["--version-check"])
context = self.make_dbt_context("child", ["--version-check"], parent_context)
with pytest.raises(DbtUsageException):
Flags(context)

@github-actions
Copy link
Contributor

The backport to 1.5.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.5.latest 1.5.latest
# Navigate to the new working tree
cd .worktrees/backport-1.5.latest
# Create a new branch
git switch --create backport-8670-to-1.5.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f17c1f3fe730947f554b55e4e5471bb9cb45fd95
# Push it to GitHub
git push --set-upstream origin backport-8670-to-1.5.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.5.latest

Then, create a pull request where the base branch is 1.5.latest and the compare/head branch is backport-8670-to-1.5.latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.5.latest backport 1.6.latest cla:yes user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-1737] Support all "global" flags after all subcommands
6 participants