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

expose_value=false causes crash when auto-completing. #2336

Closed
bakhtiary opened this issue Aug 6, 2022 · 1 comment · Fixed by #2556
Closed

expose_value=false causes crash when auto-completing. #2336

bakhtiary opened this issue Aug 6, 2022 · 1 comment · Fixed by #2556
Milestone

Comments

@bakhtiary
Copy link

bakhtiary commented Aug 6, 2022

setting expose_value=false for an argument causes crash when auto-completing.

To replicate:

# example.py
import click

@click.command
@click.argument('a', expose_value=False)
def main():
    pass

main()
$ _EXAMPLE_PY_COMPLETE=zsh_complete COMP_CWORD=1 COMP_WORDS="BUG " python example.py BUG

you should get something like the following

  File "/home/amir/projects/click/bug", line 13, in <module>
    gogo()
  File "/home/amir/projects/click/src/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/amir/projects/click/src/click/core.py", line 1050, in main
    self._main_shell_completion(extra, prog_name, complete_var)
  File "/home/amir/projects/click/src/click/core.py", line 1125, in _main_shell_completion
    rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction)
  File "/home/amir/projects/click/src/click/shell_completion.py", line 49, in shell_complete
    echo(comp.complete())
  File "/home/amir/projects/click/src/click/shell_completion.py", line 291, in complete
    completions = self.get_completions(args, incomplete)
  File "/home/amir/projects/click/src/click/shell_completion.py", line 272, in get_completions
    obj, incomplete = _resolve_incomplete(ctx, args, incomplete)
  File "/home/amir/projects/click/src/click/shell_completion.py", line 575, in _resolve_incomplete
    if _is_incomplete_argument(ctx, param):
  File "/home/amir/projects/click/src/click/shell_completion.py", line 439, in _is_incomplete_argument
    value = ctx.params[param.name]
KeyError: 'a'

I think the correct behavior is that nothing should happen or some thing should be printed to stdout. but it shouldn't crash

Environment:

  • Python version: 3.10
  • Click version: main
@jcrotts
Copy link
Contributor

jcrotts commented Dec 5, 2022

Changing this line to ctx.params.get(param.name) prints out the helptext for the command instead of the error, maybe preferable to changing expose_value.

@davidism davidism added this to the 8.1.4 milestone Jul 4, 2023
@davidism davidism linked a pull request Jul 6, 2023 that will close this issue
@davidism davidism closed this as completed Jul 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants