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

Callback always called twice when providing prompt_fn and callback to InteractiveOption #5023

Closed
janssenhenning opened this issue Jul 19, 2021 · 0 comments · Fixed by #5064
Closed

Comments

@janssenhenning
Copy link
Contributor

janssenhenning commented Jul 19, 2021

Describe the bug

Using both the prompt_fn and callback arguments in the InteractiveOption leads to unexpected additional calls of the callback function.

Steps to reproduce

from aiida.cmdline.params.options.interactive import InteractiveOption

def prompt_callback(ctx):
    print('prompt callback')
    return True

def callback(ctx, param, value):
    print('callback')

@click.command('test')
@click.option('--label',
              cls=InteractiveOption,
              prompt='Label',
              prompt_fn=prompt_callback,
              callback=callback)
def cmd_test(label):
    print(label)

Output:

prompt callback
Info: enter "?" for help
Info: enter "!" to ignore the default and set no value
Label: test
callback
callback
test

Expected behavior

The callback should be called only once after the sucessfull prompt

prompt callback
Info: enter "?" for help
Info: enter "!" to ignore the default and set no value
Label: test
callback
test

Your environment

  • Operating system [e.g. Linux]: MacOs
  • Python version [e.g. 3.7.1]: 3.7.7
  • aiida-core version [e.g. 1.2.1]: develop branch

Other relevant software versions, e.g. Postres & RabbitMQ
click version 7.1.2

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

Successfully merging a pull request may close this issue.

2 participants