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

Support passing args as keyword argument for run-operation in programmatic invocations #10473

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Jul 22, 2024

resolves #10355

Problem

As described in #10355, there's a naming conflict between the first parameter of dbtRunner.invoke() and the --args CLI flag of the run-operation command.

Solution

  1. Make the first parameter positional-only
  2. Rename the first parameter from args to invocation_args
  3. Allow run_dbt and run_dbt_and_capture test utilities to take optional kwargs parameters for testing purposes
  4. Update the small handful of places that were using a keyword parameter rather than positional

Interface changes

These interface changes assume that the intended and dominant usage of dbtRunner.invoke is a positional first argument along with optional kwargs:

  • Within dbtRunner.invoke rename args to invocation_args and explicitly make it positional
  • Align run_dbt and run_dbt_and_capture with those same changes

If anyone has code like dbtRunner().invoke(args=["run", ...]) they would need to update it by removing args=.

Testing strategy

Indirectly testing dbtRunner().invoke() via run_dbt_and_capture & run_dbt -- added this new test to verify that custom args makes it through:

    def test_args_as_keyword(self, project):
        results, log_output = run_dbt_and_capture(
            ["run-operation", "print_something"], args={"message": "Morning coffee"}
        )
        assert "Morning coffee" in log_output

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 interface changes and it has already received feedback and approval from Product or DX
  • Modified function already includes type annotations

@dbeatty10 dbeatty10 added user docs [docs.getdbt.com] Needs better documentation Skip Changelog Skips GHA to check for changelog file labels Jul 22, 2024
@cla-bot cla-bot bot added the cla:yes label Jul 22, 2024
@dbeatty10 dbeatty10 removed the Skip Changelog Skips GHA to check for changelog file label Jul 22, 2024
Copy link

codecov bot commented Jul 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.80%. Comparing base (c668846) to head (9c3fa09).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10473      +/-   ##
==========================================
- Coverage   88.86%   88.80%   -0.06%     
==========================================
  Files         180      180              
  Lines       22560    22573      +13     
==========================================
  Hits        20047    20047              
- Misses       2513     2526      +13     
Flag Coverage Δ
integration 86.02% <100.00%> (-0.18%) ⬇️
unit 62.22% <25.00%> (+0.08%) ⬆️

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

Components Coverage Δ
Unit Tests 62.22% <25.00%> (+0.08%) ⬆️
Integration Tests 86.02% <100.00%> (-0.18%) ⬇️

@dbeatty10 dbeatty10 changed the title Support passing --args for run-operation in programmatic invocations Support passing args as keyword argument for run-operation in programmatic invocations Jul 23, 2024
@dbeatty10 dbeatty10 marked this pull request as ready for review July 31, 2024 13:38
@dbeatty10 dbeatty10 requested a review from a team as a code owner July 31, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Can't pass args for run-operation in programmatic invocation as kwarg
1 participant