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

get_parameter_source does not work with invoke or forward #2753

Open
bretwalker opened this issue Jul 15, 2024 · 0 comments
Open

get_parameter_source does not work with invoke or forward #2753

bretwalker opened this issue Jul 15, 2024 · 0 comments

Comments

@bretwalker
Copy link

When invoking one Click command from another using either invoke or forward, get_parameter_source does not appear to work as it does if the command were called directly.

Sample code:

import click

cli = click.Group()

@cli.command()
@click.option('--count', default=1)
@click.pass_context
def test(ctx, count):
    click.echo(f'Count: {count}')
    click.echo(f'ctx.get_parameter_source: {ctx.get_parameter_source("count")}')
    click.echo(f'ctx.parent.get_parameter_source: {ctx.parent.get_parameter_source("count") if ctx.parent else None}')

@cli.command()
@click.option('--count', default=1)
@click.pass_context
def dist(ctx, count):
    click.echo("Calling directly")
    test(standalone_mode=False)
    click.echo("Forwarding")
    ctx.forward(test)
    click.echo("Invoking")
    ctx.invoke(test, count=42)

if __name__ == '__main__':
    dist()

Results:

Calling directly
Count: 1
ctx.get_parameter_source: ParameterSource.DEFAULT
ctx.parent.get_parameter_source: None
Forwarding
Count: 1
ctx.get_parameter_source: None
ctx.parent.get_parameter_source: ParameterSource.DEFAULT
Invoking
Count: 42
ctx.get_parameter_source: None
ctx.parent.get_parameter_source: ParameterSource.DEFAULT

I would expect ctx.get_parameter_source to be ParameterSource.DEFAULT for the calls made using invoke and forward or for the differing behavior to be explicitly mentioned in the get_parameter_source documentation. I ran into this issue when wrapping a dbt command, so I believe I'm not the only one that expects not to have to check a parent's get_parameter_source (dbt source).

Thank you for your help.

Environment:

  • Python version: Python 3.9.17
  • Click version: 8.1.7
@bretwalker bretwalker changed the title get_parameter_source does not work in with invoke or forward get_parameter_source does not work with invoke or forward Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant